diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 4980fb72..b5c43e6a 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -173,6 +173,21 @@ class NoteClub(Note): def pretty(self): return _("Note of %(club)s club") % {'club': str(self.club)} + def save(self, *args, **kwargs): + if self.pk and self.balance < 0: + old_note = NoteClub.objects.get(pk=self.pk) + if old_note.balance >= 0: + # Passage en négatif + self.last_negative = timezone.now() + self.send_mail_negative_balance() + super().save(*args, **kwargs) + + def send_mail_negative_balance(self): + plain_text = render_to_string("note/mails/negative_balance.txt", dict(note=self)) + html = render_to_string("note/mails/negative_balance.html", dict(note=self)) + self.user.email_user("[Note Kfet] Passage en négatif (club {})" + .format(self.club.name), plain_text, html_message=html) + class NoteSpecial(Note): """ diff --git a/apps/note/templates/note/mails/negative_balance.html b/apps/note/templates/note/mails/negative_balance.html index 180c4385..ef532998 100644 --- a/apps/note/templates/note/mails/negative_balance.html +++ b/apps/note/templates/note/mails/negative_balance.html @@ -10,7 +10,7 @@
- Bonjour {{ note.user.first_name }} {{ note.user.last_name }}, + Bonjour {{ note }},
diff --git a/apps/note/templates/note/mails/negative_balance.txt b/apps/note/templates/note/mails/negative_balance.txt index f0ee4a21..f257194d 100644 --- a/apps/note/templates/note/mails/negative_balance.txt +++ b/apps/note/templates/note/mails/negative_balance.txt @@ -2,7 +2,7 @@ {% load getenv %} {% load i18n %} -Bonjour {{ note.user.first_name }} {{ note.user.last_name }}, +Bonjour {{ note }}, Ce mail t'a été envoyé parce que le solde de ta Note Kfet {{ note }} est négatif ! diff --git a/apps/note/templates/note/mails/negative_notes_report.html b/apps/note/templates/note/mails/negative_notes_report.html index 434c2d4d..49254f5d 100644 --- a/apps/note/templates/note/mails/negative_notes_report.html +++ b/apps/note/templates/note/mails/negative_notes_report.html @@ -22,10 +22,17 @@
{% for note in notes %}