Settlement: rename variables to make the code more understandable

This commit is contained in:
Baptiste Jonglez 2024-03-29 17:27:15 +01:00
parent a5f83de5ce
commit d6291a97e6
2 changed files with 14 additions and 14 deletions

View file

@ -11,14 +11,14 @@
<table id="bill_table" class="split_bills table table-striped">
<thead><tr><th>{{ _("Who pays?") }}</th><th>{{ _("To whom?") }}</th><th>{{ _("How much?") }}</th><th>{{ _("Settled?") }}</th></tr></thead>
<tbody>
{% for bill in bills %}
<tr receiver={{bill.receiver.id}}>
<td>{{ bill.ower }}</td>
<td>{{ bill.receiver }}</td>
<td>{{ bill.amount|currency }}</td>
{% for transaction in transactions %}
<tr receiver={{transaction.receiver.id}}>
<td>{{ transaction.ower }}</td>
<td>{{ transaction.receiver }}</td>
<td>{{ transaction.amount|currency }}</td>
<td>
<span id="settle-bill" class="ml-auto pb-2">
<a href="{{ url_for('.settle', amount = bill.amount, ower_id = bill.ower.id, payer_id = bill.receiver.id) }}" class="btn btn-primary">
<a href="{{ url_for('.add_settlement_bill', amount = transaction.amount, sender_id = transaction.ower.id, receiver_id = transaction.receiver.id) }}" class="btn btn-primary">
{{ ("Settle") }}
</a>
</span>

View file

@ -846,24 +846,24 @@ def change_lang(lang):
@main.route("/<project_id>/settle_bills")
def settle_bill():
"""Compute the sum each one have to pay to each other and display it"""
bills = g.project.get_transactions_to_settle_bill()
return render_template("settle_bills.html", bills=bills, current_view="settle_bill")
transactions = g.project.get_transactions_to_settle_bill()
return render_template("settle_bills.html", transactions=transactions, current_view="settle_bill")
@main.route("/<project_id>/settle/<amount>/<int:ower_id>/<int:payer_id>")
def settle(amount, ower_id, payer_id):
new_reinbursement = Bill(
@main.route("/<project_id>/settle/<amount>/<int:sender_id>/<int:receiver_id>")
def add_settlement_bill(amount, sender_id, receiver_id):
settlement = Bill(
amount=float(amount),
date=datetime.datetime.today(),
owers=[Person.query.get(payer_id)],
payer_id=ower_id,
owers=[Person.query.get(receiver_id)],
payer_id=sender_id,
project_default_currency=g.project.default_currency,
bill_type=BillType.REIMBURSEMENT,
what=_("Settlement"),
)
session.update()
db.session.add(new_reinbursement)
db.session.add(settlement)
db.session.commit()
return redirect(url_for(".settle_bill"))