Browse Source

From payment, update accounting only if created or non allocated

Alexandre Aubin 7 years ago
parent
commit
5fe61506c4
1 changed files with 8 additions and 6 deletions
  1. 8 6
      coin/billing/models.py

+ 8 - 6
coin/billing/models.py

@@ -392,11 +392,6 @@ class Payment(models.Model):
     def save(self, *args, **kwargs):
         super(Payment, self).save(*args, **kwargs)
 
-        # If this payment is related to a member, update the accounting for
-        # this member
-        if self.member is not None:
-            update_accounting_for_member(self.member)
-
     def amount_not_allocated(self):
         return self.amount - self.amount_already_allocated
 
@@ -582,16 +577,23 @@ def test_accounting_update():
 
 @receiver(post_save, sender=Payment)
 def payment_changed(sender, instance, created, **kwargs):
+
     if created:
         accounting_log.info("Adding payment %s (Date: %s, Member: %s, Amount: %s, Label: %s)."
                             % (instance.pk, instance.date, instance.member,
                                 instance.amount, instance.label))
     else:
-        accounting_log.info("Updating payment %s (Date: %s, Member: %s, Amount: %s, Label: %s, Allocated : )%s."
+        accounting_log.info("Updating payment %s (Date: %s, Member: %s, Amount: %s, Label: %s, Allocated: %s)."
                             % (instance.pk, instance.date, instance.member,
                                 instance.amount, instance.label,
                                 instance.amount_already_allocated))
 
+    # If this payment is related to a member, update the accounting for
+    # this member
+    if (created or instance.amount_not_allocated != 0) \
+    and (instance.member is not None):
+        update_accounting_for_member(instance.member)
+
 
 @receiver(post_save, sender=Invoice)
 def invoice_changed(sender, instance, created, **kwargs):