Merge pull request #5 from FlowingCloudRTL/yiqunz-settle-button

Yiqunz settle button
This commit is contained in:
Ruitao Li 2022-12-12 19:24:17 -05:00 committed by GitHub
commit 5fc8b822a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View file

@ -33,3 +33,6 @@ restful_api.add_resource(BillsHandler, "/projects/<string:project_id>/bills")
restful_api.add_resource(
BillHandler, "/projects/<string:project_id>/bills/<int:bill_id>"
)
# restful_api.add_resource(
# ProjectHandler, "/<project_id>/settle/<amount>/<ower>/<payer>"
# )

View file

@ -9,13 +9,20 @@
{% 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></tr></thead>
<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>
<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">
{{ ("Settle") }}
</a>
</span>
</td>
</tr>
{% endfor %}
</tbody>

View file

@ -8,6 +8,7 @@ Basically, this blueprint takes care of the authentication and provides
some shortcuts to make your life better when coding (see `pull_project`
and `add_project_id` for a quick overview)
"""
import datetime
from functools import wraps
import json
import os
@ -810,6 +811,34 @@ def settle_bill():
return render_template("settle_bills.html", bills=bills, current_view="settle_bill")
@main.route("/<project_id>/settle/<amount>/<int:ower_id>/<int:payer_id>")
def settle(amount, ower_id, payer_id):
# FIXME: Test this bill belongs to this project !
# form = get_billform_for(g.project, set_default=False)
# form.bill_type = ("Refund", "Refund")
# form.amount = amount
# form.payer = ower
# form.payedfor = payer
new_reinbursement = Bill(
amount=float(amount),
date=datetime.datetime.today(),
owers=[Person.query.get(payer_id)],
payer_id=ower_id,
project_default_currency=g.project.default_currency,
bill_type="Reimbursement",
what="settlement"
)
session.update()
db.session.add(new_reinbursement)
db.session.commit()
# db.session.add(form.export(g.project))
# db.session.commit()
return redirect(url_for(".settle_bill"))
@main.route("/<project_id>/history")
def history():
"""Query for the version entries associated with this project."""