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

Improve add permissions

This commit is contained in:
Yohann D'ANELLO
2020-03-18 15:49:52 +01:00
parent 057f42fdb6
commit e461d70b14
3 changed files with 24 additions and 7 deletions

View File

@ -129,14 +129,13 @@ class Transaction(PolymorphicModel):
models.Index(fields=['destination']),
]
def save(self, *args, **kwargs):
def post_save(self, *args, **kwargs):
"""
When saving, also transfer money between two notes
"""
if self.source.pk == self.destination.pk:
# When source == destination, no money is transfered
super().save(*args, **kwargs)
return
created = self.pk is None
@ -152,10 +151,12 @@ class Transaction(PolymorphicModel):
self.source.balance -= to_transfer
self.destination.balance += to_transfer
# We save first the transaction, in case of the user has no right to transfer money
super().save(*args, **kwargs)
# Save notes
self.source.save()
self.destination.save()
super().save(*args, **kwargs)
@property
def total(self):