Make it possible to display negative weights values

This commit is contained in:
Alexis Métaireau 2018-08-05 16:57:13 +02:00
parent ef7f1f94c5
commit e89a758db5
2 changed files with 5 additions and 2 deletions

View file

@ -151,7 +151,7 @@ class BillForm(FlaskForm):
class MemberForm(FlaskForm): class MemberForm(FlaskForm):
name = StringField(_("Name"), validators=[Required()]) name = StringField(_("Name"), validators=[Required()])
wieght_validators = [NumberRange(min=0.1, message=_("Weights should be positive"))] weight_validators = [NumberRange(min=0.1, message=_("Weights should be positive"))]
weight = CommaDecimalField(_("Weight"), default=1, weight = CommaDecimalField(_("Weight"), default=1,
validators=weight_validators) validators=weight_validators)
submit = SubmitField(_("Add")) submit = SubmitField(_("Add"))

View file

@ -346,7 +346,10 @@ class Bill(db.Model):
"""Compute what each share has to pay""" """Compute what each share has to pay"""
if self.owers: if self.owers:
# FIXME: SQL might dot that more efficiently # FIXME: SQL might dot that more efficiently
return self.amount / sum(i.weight for i in self.owers) weights = sum(i.weight for i in self.owers)
if weights <= 0:
weights = 1
return self.amount / weights
else: else:
return 0 return 0