mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 12:41:49 +02:00
Make it possible to display negative weights values
This commit is contained in:
parent
ef7f1f94c5
commit
e89a758db5
2 changed files with 5 additions and 2 deletions
|
@ -151,7 +151,7 @@ class BillForm(FlaskForm):
|
|||
class MemberForm(FlaskForm):
|
||||
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,
|
||||
validators=weight_validators)
|
||||
submit = SubmitField(_("Add"))
|
||||
|
|
|
@ -346,7 +346,10 @@ class Bill(db.Model):
|
|||
"""Compute what each share has to pay"""
|
||||
if self.owers:
|
||||
# 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:
|
||||
return 0
|
||||
|
||||
|
|
Loading…
Reference in a new issue