diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index c818b75b..701e7c58 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -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")) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index c6ce23fb..1ba3f7ba 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -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