mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 09:58:23 +02:00
Use a signal to prevent a user that the note balance is negative
This commit is contained in:
@ -159,20 +159,6 @@ class NoteUser(Note):
|
||||
def pretty(self):
|
||||
return _("%(user)s's note") % {'user': str(self.user)}
|
||||
|
||||
@transaction.atomic
|
||||
def save(self, *args, **kwargs):
|
||||
if self.pk and self.balance < 0:
|
||||
old_note = NoteUser.objects.get(pk=self.pk)
|
||||
super().save(*args, **kwargs)
|
||||
if old_note.balance >= 0:
|
||||
# Passage en négatif
|
||||
self.last_negative = timezone.now()
|
||||
self._force_save = True
|
||||
self.save(*args, **kwargs)
|
||||
self.send_mail_negative_balance()
|
||||
else:
|
||||
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))
|
||||
@ -201,20 +187,6 @@ class NoteClub(Note):
|
||||
def pretty(self):
|
||||
return _("Note of %(club)s club") % {'club': str(self.club)}
|
||||
|
||||
@transaction.atomic
|
||||
def save(self, *args, **kwargs):
|
||||
if self.pk and self.balance < 0:
|
||||
old_note = NoteClub.objects.get(pk=self.pk)
|
||||
super().save(*args, **kwargs)
|
||||
if old_note.balance >= 0:
|
||||
# Passage en négatif
|
||||
self.last_negative = timezone.now()
|
||||
self._force_save = True
|
||||
self.save(*args, **kwargs)
|
||||
self.send_mail_negative_balance()
|
||||
else:
|
||||
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))
|
||||
|
Reference in New Issue
Block a user