1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-21 01:48:21 +02:00

Give a reason when a transaction is invalidated

This commit is contained in:
Yohann D'ANELLO
2020-03-25 13:13:01 +01:00
parent 0ac94547d1
commit 23db42e448
3 changed files with 59 additions and 12 deletions

View File

@ -115,11 +115,19 @@ class Transaction(PolymorphicModel):
verbose_name=_('reason'),
max_length=255,
)
valid = models.BooleanField(
verbose_name=_('valid'),
default=True,
)
invalidity_reason = models.CharField(
verbose_name=_('invalidity reason'),
max_length=255,
default=None,
null=True,
)
class Meta:
verbose_name = _("transaction")
verbose_name_plural = _("transactions")
@ -152,6 +160,10 @@ class Transaction(PolymorphicModel):
self.source.balance -= to_transfer
self.destination.balance += to_transfer
# When a transaction is declared valid, we ensure that the invalidity reason is null, if it was
# previously invalid
self.invalidity_reason = None
# We save first the transaction, in case of the user has no right to transfer money
super().save(*args, **kwargs)