Settlement: rename variables to make the code more understandable

This commit is contained in:
Baptiste Jonglez 2024-03-29 17:27:15 +01:00 committed by Alexis Métaireau
parent bd689f931a
commit 9a834c97e3
No known key found for this signature in database
GPG key ID: 1C21B876828E5FF2
2 changed files with 43 additions and 37 deletions

View file

@ -1,25 +1,31 @@
{% extends "sidebar_table_layout.html" %}
{% block sidebar %}
<div id="table_overflow">
{{ balance_table(show_weight=False) }}
</div>
{% endblock %}
{% block content %}
<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>
{% extends "sidebar_table_layout.html" %} {% block sidebar %}
<div id="table_overflow">{{ balance_table(show_weight=False) }}</div>
{% endblock %} {% block content %}
<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">
<div data-toggle="tooltip" title='{{ _("Click here to record that the money transfer has been done") }}'>
<a
href="{{ url_for('.add_settlement_bill', amount = transaction.amount, sender_id = transaction.ower.id, receiver_id = transaction.receiver.id) }}"
class="btn btn-primary"
>
<div
data-toggle="tooltip"
title='{{ _("Click here to record that the money transfer has been done") }}'
>
{{ ("Settle") }}
</div>
</a>
@ -28,6 +34,6 @@
</tr>
{% endfor %}
</tbody>
</table>
</table>
{% endblock %}

View file

@ -852,24 +852,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()
flash(_("Settlement bill has been successfully added"), category="success")