|
@@ -19,7 +19,7 @@ class InvoiceDetailInline(LimitedAdminInlineMixin, admin.StackedInline):
|
|
|
model = InvoiceDetail
|
|
|
extra = 0
|
|
|
fields = (('label', 'amount', 'quantity', 'tax'),
|
|
|
- ('offersubscription','period_from', 'period_to'))
|
|
|
+ ('offersubscription', 'period_from', 'period_to'))
|
|
|
|
|
|
def get_filters(self, obj):
|
|
|
"""
|
|
@@ -28,7 +28,7 @@ class InvoiceDetailInline(LimitedAdminInlineMixin, admin.StackedInline):
|
|
|
une liste vide
|
|
|
"""
|
|
|
if obj and obj.member:
|
|
|
- return (('offersubscription', {'member':obj.member}),)
|
|
|
+ return (('offersubscription', {'member': obj.member}),)
|
|
|
else:
|
|
|
return (('offersubscription', None),)
|
|
|
|
|
@@ -39,6 +39,7 @@ class InvoiceDetailInline(LimitedAdminInlineMixin, admin.StackedInline):
|
|
|
|
|
|
|
|
|
class InvoiceDetailInlineReadOnly(admin.StackedInline):
|
|
|
+
|
|
|
"""
|
|
|
Lorsque la facture est validée, il n'est plus possible de la modifier
|
|
|
Ce inline est donc identique à InvoiceDetailInline, mais tous
|
|
@@ -57,9 +58,9 @@ class InvoiceDetailInlineReadOnly(admin.StackedInline):
|
|
|
result = flatten_fieldsets(self.declared_fieldsets)
|
|
|
else:
|
|
|
result = list(set(
|
|
|
- [field.name for field in self.opts.local_fields] +
|
|
|
- [field.name for field in self.opts.local_many_to_many]
|
|
|
- ))
|
|
|
+ [field.name for field in self.opts.local_fields] +
|
|
|
+ [field.name for field in self.opts.local_many_to_many]
|
|
|
+ ))
|
|
|
result.remove('id')
|
|
|
return result
|
|
|
|
|
@@ -74,11 +75,11 @@ class InvoiceAdmin(admin.ModelAdmin):
|
|
|
list_display = ('number', 'date', 'status', 'amount', 'member', 'validated')
|
|
|
list_display_links = ('number', 'date')
|
|
|
fields = (('number', 'date', 'status'),
|
|
|
- ('date_due'),
|
|
|
- ('member'),
|
|
|
- ('amount','amount_paid'),
|
|
|
- ('validated', 'pdf'))
|
|
|
- readonly_fields = ('amount','amount_paid','validated','pdf')
|
|
|
+ ('date_due'),
|
|
|
+ ('member'),
|
|
|
+ ('amount', 'amount_paid'),
|
|
|
+ ('validated', 'pdf'))
|
|
|
+ readonly_fields = ('amount', 'amount_paid', 'validated', 'pdf')
|
|
|
form = autocomplete_light.modelform_factory(Invoice)
|
|
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
@@ -133,22 +134,26 @@ class InvoiceAdmin(admin.ModelAdmin):
|
|
|
"""
|
|
|
urls = super(InvoiceAdmin, self).get_urls()
|
|
|
my_urls = [
|
|
|
- url(r'^validate/(?P<id>.+)$', self.admin_site.admin_view(self.validate_view),
|
|
|
+ url(r'^validate/(?P<id>.+)$',
|
|
|
+ self.admin_site.admin_view(self.validate_view),
|
|
|
name='invoice_validate'),
|
|
|
]
|
|
|
return my_urls + urls
|
|
|
|
|
|
def validate_view(self, request, id):
|
|
|
"""
|
|
|
- Vue appelée lorsque l'admin souhaite valider une facture (et générer le pdf)
|
|
|
+ Vue appelée lorsque l'admin souhaite valider une facture et
|
|
|
+ générer son pdf
|
|
|
"""
|
|
|
- #TODO : Add better perm here
|
|
|
+ # TODO : Add better perm here
|
|
|
if request.user.is_superuser:
|
|
|
invoice = get_invoice_from_id_or_number(id)
|
|
|
invoice.validate()
|
|
|
messages.success(request, 'La facture a été validée.')
|
|
|
else:
|
|
|
- messages.error(request, 'Vous n\'avez pas l\'autorisation de valider une facture.')
|
|
|
+ messages.error(
|
|
|
+ request, 'Vous n\'avez pas l\'autorisation de valider '
|
|
|
+ 'une facture.')
|
|
|
|
|
|
return HttpResponseRedirect(request.META["HTTP_REFERER"])
|
|
|
|