Browse Source

Fix ValidationError re-opening an invoice in admin

Ref #186
Jocelyn Delalande 6 years ago
parent
commit
28026e6c3f
1 changed files with 10 additions and 0 deletions
  1. 10 0
      coin/billing/admin.py

+ 10 - 0
coin/billing/admin.py

@@ -103,6 +103,11 @@ class PaymentInlineAdd(admin.StackedInline):
         return False
 
 
+class DummyPaymentInlineAdd(PaymentInlineAdd):
+    def has_add_permission(self, request):
+        return False
+
+
 class InvoiceAdmin(admin.ModelAdmin):
     list_display_links = ('number', 'date')
     list_filter = ('status', 'validated', 'date')
@@ -156,6 +161,11 @@ class InvoiceAdmin(admin.ModelAdmin):
                 inlines += [PaymentAllocatedReadOnly]
                 if obj.status == "open":
                     inlines += [PaymentInlineAdd]
+                else:
+                    # if we do not provide any inline, coin will yell on
+                    # closed->open status, expecting POST data with Payment
+                    # inline data. Thus, we provide an empty.
+                    inlines += [DummyPaymentInlineAdd]
 
         for inline_class in inlines:
             inline = inline_class(self.model, self.admin_site)