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:
@ -1,6 +1,8 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def save_user_note(instance, raw, **_kwargs):
|
||||
"""
|
||||
@ -25,6 +27,16 @@ def save_club_note(instance, raw, **_kwargs):
|
||||
instance.note.save()
|
||||
|
||||
|
||||
def pre_save_note(instance, raw, **_kwargs):
|
||||
if not raw and instance.pk and not hasattr(instance, "_no_signal") and instance.balance < 0:
|
||||
from note.models import Note
|
||||
old_note = Note.objects.get(pk=instance.pk)
|
||||
if old_note.balance >= 0:
|
||||
# Passage en négatif
|
||||
instance.last_negative = timezone.now()
|
||||
instance.send_mail_negative_balance()
|
||||
|
||||
|
||||
def delete_transaction(instance, **_kwargs):
|
||||
"""
|
||||
Whenever we want to delete a transaction (caution with this), we ensure the transaction is invalid first.
|
||||
|
Reference in New Issue
Block a user