From 70c54f96c710ec3a148f4563491dd0c4ed49e60e Mon Sep 17 00:00:00 2001 From: detraz Date: Sat, 1 Sep 2018 02:12:19 +0200 Subject: [PATCH] Post save custom dans la fonction save, pour __original_valid --- cotisations/models.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cotisations/models.py b/cotisations/models.py index 15d2e39d..0c9ef171 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -233,10 +233,14 @@ class Facture(BaseInvoice): } self.__original_valid = self.valid + def save(self, *args, **kwargs): + super(Facture, self).save(*args, **kwargs) + if not self.__original_valid and self.valid: + send_mail_invoice(self) + def __str__(self): return str(self.user) + ' ' + str(self.date) - @receiver(post_save, sender=Facture) def facture_post_save(**kwargs): """ @@ -245,10 +249,8 @@ def facture_post_save(**kwargs): facture = kwargs['instance'] if facture.valid: user = facture.user - if not facture.__original_valid: - user.set_active() - send_mail_invoice(facture) - user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + user.set_active() + user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) @receiver(post_delete, sender=Facture)