From e89a758db58688f2ff2d03166defc20d556a6d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Sun, 5 Aug 2018 16:57:13 +0200 Subject: [PATCH] Make it possible to display negative weights values --- ihatemoney/forms.py | 2 +- ihatemoney/models.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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