diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 4980fb729cd7275de125f74266e14a1dc6a2407c..b5c43e6a4a616377acac0183b271ff0fe9321fb9 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 180c43857520f8865071d9070b3857190b7b9520..ef53299898e8658052fa23e3618b49a9e215170f 100644 --- a/apps/note/templates/note/mails/negative_balance.html +++ b/apps/note/templates/note/mails/negative_balance.html @@ -10,7 +10,7 @@ </head> <body> <p> - Bonjour {{ note.user.first_name }} {{ note.user.last_name }}, + Bonjour {{ note }}, </p> <p> diff --git a/apps/note/templates/note/mails/negative_balance.txt b/apps/note/templates/note/mails/negative_balance.txt index f0ee4a2154baa372688ebcd94fac96d9e366356e..f257194d6f91cbd0bbe6b45abb50bfeee335ab98 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 434c2d4d593965aff59c858c766dea494c9ba0b0..49254f5d4ff63025da0349d296e5e570b7c4276b 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 @@ <tbody> {% for note in notes %} <tr> - <td>{{ note.user.last_name }}</td> - <td>{{ note.user.first_name }}</td> - <td>{{ note.user.username }}</td> - <td>{{ note.user.email }}</td> + {% if note.user %} + <td>{{ note.user.last_name }}</td> + <td>{{ note.user.first_name }}</td> + <td>{{ note.user.username }}</td> + <td>{{ note.user.email }}</td> + {% else %} + <td></td> + <td></td> + <td>{{ note.club.name }}</td> + <td>{{ note.club.email }}</td> + {% endif %} <td>{{ note.balance|pretty_money }}</td> <td>{{ note.last_negative_duration }}</td> </tr> diff --git a/apps/note/templates/note/mails/negative_notes_report.txt b/apps/note/templates/note/mails/negative_notes_report.txt index ead5b5fb6dd396bf17820242143c0561fa06fb86..3209fbb824a22237548d4b3192f10c4bd64b7b01 100644 --- a/apps/note/templates/note/mails/negative_notes_report.txt +++ b/apps/note/templates/note/mails/negative_notes_report.txt @@ -4,7 +4,7 @@ Nom | Prénom | Pseudo | Email | Solde | Durée ---------------------+------------+-----------------+-----------------------------------+----------+----------- {% for note in notes %} -{{ note.user.last_name }} | {{ note.user.first_name }} | {{ note.user.username }} | {{ note.user.email }} | {{ note.balance|pretty_money }} | {{ note.last_negative_duration }} +{% if note.user %}{{ note.user.last_name }} | {{ note.user.first_name }} | {{ note.user.username }} | {{ note.user.email }} | {{ note.balance|pretty_money }} | {{ note.last_negative_duration }}{% else %} | | {{ note.club.name }} | {{ note.club.email }} | {{ note.balance|pretty_money }} | {{ note.last_negative_duration }}{% endif %} {% endfor %} -- diff --git a/apps/scripts b/apps/scripts index 4179cad611151d2b66da3fc87cebcb5317779cb2..2b1c05ff98327cfda8ea968376c3b47d6f2aeccb 160000 --- a/apps/scripts +++ b/apps/scripts @@ -1 +1 @@ -Subproject commit 4179cad611151d2b66da3fc87cebcb5317779cb2 +Subproject commit 2b1c05ff98327cfda8ea968376c3b47d6f2aeccb