From f0ff9186798a7c8032fb4a90b94beec5fa9632fd Mon Sep 17 00:00:00 2001 From: Rebecca J Date: Thu, 8 Dec 2022 23:07:46 -0500 Subject: [PATCH] added reimbursement field in add bill form --- ihatemoney/forms.py | 2 ++ ihatemoney/models.py | 5 +++++ ihatemoney/templates/forms.html | 1 + ihatemoney/templates/settle_bills.html | 5 +++++ ihatemoney/web.py | 22 ++++++++++++++++++++++ 5 files changed, 35 insertions(+) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index c4fc32a8..62f4f979 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -325,6 +325,7 @@ class BillForm(FlaskForm): what = StringField(_("What?"), validators=[DataRequired()]) payer = SelectField(_("Who paid?"), validators=[DataRequired()], coerce=int) amount = CalculatorStringField(_("How much?"), validators=[DataRequired()]) + is_reimbursement = BooleanField("Reimbursement", default=False) currency_helper = CurrencyConverter() original_currency = SelectField(_("Currency"), validators=[DataRequired()]) external_link = URLField( @@ -344,6 +345,7 @@ class BillForm(FlaskForm): amount=float(self.amount.data), date=self.date.data, external_link=self.external_link.data, + is_reimbursement=self.is_reimbursement.data, original_currency=str(self.original_currency.data), owers=Person.query.get_by_ids(self.payed_for.data, project), payer_id=self.payer.data, diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 10615d42..a1402090 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -159,6 +159,11 @@ class Project(db.Model): monthly = defaultdict(lambda: defaultdict(float)) for bill in self.get_bills_unordered().all(): monthly[bill.date.year][bill.date.month] += bill.converted_amount +======= + if (bill.is_reimbursement == False): + # if (not bill.what.startswith("R-")): + monthly[bill.date.year][bill.date.month] += bill.converted_amount +>>>>>>> Stashed changes return monthly @property diff --git a/ihatemoney/templates/forms.html b/ihatemoney/templates/forms.html index 48c3df2b..83116859 100644 --- a/ihatemoney/templates/forms.html +++ b/ihatemoney/templates/forms.html @@ -166,6 +166,7 @@ {{ input(form.date, inline=True) }} {{ input(form.what, inline=True) }} {{ input(form.payer, inline=True, class="form-control custom-select") }} + {{ input(form.is_reimbursement, inline=True) }}
{{ input(form.amount, inline=True) }}
diff --git a/ihatemoney/templates/settle_bills.html b/ihatemoney/templates/settle_bills.html index 601156c6..dbad835d 100644 --- a/ihatemoney/templates/settle_bills.html +++ b/ihatemoney/templates/settle_bills.html @@ -16,6 +16,11 @@ {{ bill.ower }} {{ bill.receiver }} {{ bill.amount|currency }} + {% endfor %} diff --git a/ihatemoney/web.py b/ihatemoney/web.py index c2f19c06..0de46fdd 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -747,6 +747,28 @@ def add_bill(): return render_template("add_bill.html", form=form) +@main.route("//settle_bills/add", methods=["GET", "POST"]) +def settle(): + form = get_billform_for(g.project) + if request.method == "POST": + if form.validate(): + # save last selected payer in session + session["last_selected_payer"] = form.payer.data + session.update() + + db.session.add(form.export(g.project)) + db.session.commit() + + flash(_("The bill has been added")) + + args = {} + if form.submit2.data: + args["add_bill"] = True + + return redirect(url_for(".list_bills", **args)) + + return render_template("add_bill.html", form=form) + @main.route("//delete/", methods=["POST"]) def delete_bill(bill_id):