Ecocup limit comments

This commit is contained in:
Antoine Bartuccio 2017-08-15 14:03:56 +02:00
parent 748e3ae326
commit de4521c192
2 changed files with 9 additions and 0 deletions

View File

@ -81,6 +81,11 @@ class Customer(models.Model):
return number + letter return number + letter
def save(self, allow_negative=False, is_selling=False, *args, **kwargs): def save(self, allow_negative=False, is_selling=False, *args, **kwargs):
"""
is_selling : tell if the current action is a selling
allow_negative : ignored if not a selling. Allow a selling to put the account in negative
Those two parameters avoid blocking the save method of a customer if his account is negative
"""
if self.amount < 0 and (is_selling and not allow_negative): if self.amount < 0 and (is_selling and not allow_negative):
raise ValidationError(_("Not enough money")) raise ValidationError(_("Not enough money"))
super(Customer, self).save(*args, **kwargs) super(Customer, self).save(*args, **kwargs)
@ -393,6 +398,9 @@ class Selling(models.Model):
) )
def save(self, allow_negative=False, *args, **kwargs): def save(self, allow_negative=False, *args, **kwargs):
"""
allow_negative : Allow this selling to use more money than available for this user
"""
if not self.date: if not self.date:
self.date = timezone.now() self.date = timezone.now()
self.full_clean() self.full_clean()

View File

@ -401,6 +401,7 @@ SITH_ECOCUP_CONS = 1152
SITH_ECOCUP_DECO = 1151 SITH_ECOCUP_DECO = 1151
# The limit is the maximum difference between cons and deco possible for a customer
SITH_ECOCUP_LIMIT = 3 SITH_ECOCUP_LIMIT = 3
# Defines pagination for cash summary # Defines pagination for cash summary