Browse Source

Close invoice only if amount_paid >= amount

Corrects a bug where the methods where compared instead of their return
values (missing parentheses). Fix by Jocelyn.
Jérémie Pierson 8 years ago
parent
commit
c58fa7a808
2 changed files with 17 additions and 1 deletions
  1. 1 1
      coin/billing/models.py
  2. 16 0
      coin/billing/tests.py

+ 1 - 1
coin/billing/models.py

@@ -300,7 +300,7 @@ def set_invoice_as_paid_if_needed(sender, instance, **kwargs):
     Lorsqu'un paiement est enregistré, vérifie si la facture est alors
     complétement payée. Dans ce cas elle passe en réglée
     """
-    if (instance.invoice.amount_paid >= instance.invoice.amount and
+    if (instance.invoice.amount_paid() >= instance.invoice.amount() and
             instance.invoice.status == 'open'):
         instance.invoice.status = 'closed'
         instance.invoice.save()

+ 16 - 0
coin/billing/tests.py

@@ -135,6 +135,22 @@ class BillingInvoiceCreationTests(TestCase):
         
         self.assertEqual(invoice.amount(), 111)
 
+    def test_invoice_partial_payment(self):
+        invoice = Invoice(member=self.member)
+        invoice.save()
+
+        invoice.details.create(label=self.offer.name,
+                               amount=100,
+                               offersubscription=self.subscription,
+                               period_from=datetime.date(2014, 1, 1),
+                               period_to=datetime.date(2014, 3, 31),
+                               tax=0)
+        self.assertEqual(invoice.status, 'open')
+        invoice.payments.create(payment_mean='cash', amount=10)
+        self.assertEqual(invoice.status, 'open')
+        invoice.payments.create(payment_mean='cash', amount=90)
+        self.assertEqual(invoice.status, 'closed')
+
     def test_invoice_amount_before_tax(self):
         invoice = Invoice(member=self.member)
         invoice.save()