From 42818cbe0b388db5787ab21e763e5cb244fe8c50 Mon Sep 17 00:00:00 2001 From: detraz Date: Sun, 26 Aug 2018 19:36:04 +0200 Subject: [PATCH] Fix bug send_mail + factorisation --- cotisations/models.py | 5 ++++- cotisations/utils.py | 2 +- cotisations/views.py | 6 +----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cotisations/models.py b/cotisations/models.py index fe89aa5d..97866ab5 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -50,7 +50,7 @@ from machines.models import regen from re2o.field_permissions import FieldPermissionModelMixin from re2o.mixins import AclMixin, RevMixin -from cotisations.utils import find_payment_method +from cotisations.utils import send_mail_invoice, find_payment_method from cotisations.validators import check_no_balance @@ -242,7 +242,10 @@ def facture_post_save(**kwargs): Synchronise the LDAP user after an invoice has been saved. """ facture = kwargs['instance'] + is_created = kwargs['created'] user = facture.user + if is_created: + send_mail_invoice(facture) user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) diff --git a/cotisations/utils.py b/cotisations/utils.py index 0211dd40..a8c2768e 100644 --- a/cotisations/utils.py +++ b/cotisations/utils.py @@ -89,7 +89,7 @@ def send_mail_invoice(invoice): 'Votre facture / Your invoice', template.render(ctx), GeneralOption.get_cached_value('email_from'), - [invoice.user.email], + [invoice.user.get_mail], attachments=[('invoice.pdf', pdf, 'application/pdf')] ) mail.send() diff --git a/cotisations/views.py b/cotisations/views.py index 82db074b..dc2b7875 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -81,7 +81,7 @@ from .forms import ( ) from .tex import render_invoice from .payment_methods.forms import payment_method_factory -from .utils import find_payment_method, send_mail_invoice +from .utils import find_payment_method @login_required @@ -148,8 +148,6 @@ def new_facture(request, user, userid): p.facture = new_invoice_instance p.save() - send_mail_invoice(new_invoice_instance) - return new_invoice_instance.paiement.end_payment( new_invoice_instance, request @@ -848,8 +846,6 @@ def credit_solde(request, user, **_kwargs): number=1 ) - send_mail_invoice(invoice) - return invoice.paiement.end_payment(invoice, request) p = get_object_or_404(Paiement, is_balance=True) return form({