mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
Merge 4e99980872
into 56bee93346
This commit is contained in:
commit
a177d6db8e
3 changed files with 113 additions and 14 deletions
|
@ -281,6 +281,20 @@ class Project(db.Model):
|
||||||
.order_by(Bill.id.desc())
|
.order_by(Bill.id.desc())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def filter(query, start_date, end_date, payer, owers, bill_name):
|
||||||
|
if start_date:
|
||||||
|
query = query.filter(Bill.date >= start_date)
|
||||||
|
if end_date:
|
||||||
|
query = query.filter(Bill.date <= end_date)
|
||||||
|
if payer:
|
||||||
|
query = query.filter(Bill.payer_id == payer)
|
||||||
|
if owers:
|
||||||
|
query = query.filter(Bill.owers.any(Person.id.in_(owers)))
|
||||||
|
if bill_name:
|
||||||
|
query = query.filter(Bill.what.ilike(f"%{bill_name}%"))
|
||||||
|
return query
|
||||||
|
|
||||||
def get_bill_weights(self):
|
def get_bill_weights(self):
|
||||||
"""
|
"""
|
||||||
Return all bills for this project, along with the sum of weight for each bill.
|
Return all bills for this project, along with the sum of weight for each bill.
|
||||||
|
@ -302,6 +316,10 @@ class Project(db.Model):
|
||||||
"""Ordered version of get_bill_weights"""
|
"""Ordered version of get_bill_weights"""
|
||||||
return self.order_bills(self.get_bill_weights())
|
return self.order_bills(self.get_bill_weights())
|
||||||
|
|
||||||
|
def get_filtered_bill_weights_ordered(self, start_date, end_date, payer, owers, bill_name):
|
||||||
|
return self.filter(self.get_bill_weights_ordered(), start_date=start_date, end_date=end_date, payer=payer, owers=owers, bill_name=bill_name)
|
||||||
|
|
||||||
|
|
||||||
def get_member_bills(self, member_id):
|
def get_member_bills(self, member_id):
|
||||||
"""Return the list of bills related to a specific member"""
|
"""Return the list of bills related to a specific member"""
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -105,6 +105,64 @@
|
||||||
<li class="page-item {% if bills.page == bills.pages %}disabled{% endif %}"><a class="page-link" href="{{ url_for('main.list_bills', page=bills.next_num) }}">{{ _("Older bills") }} »</a></li>
|
<li class="page-item {% if bills.page == bills.pages %}disabled{% endif %}"><a class="page-link" href="{{ url_for('main.list_bills', page=bills.next_num) }}">{{ _("Older bills") }} »</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="d-flex flex-wrap w-100 pt-2 mt-2" id="bill-toolbar">
|
||||||
|
<button class="btn btn-secondary btn-sm mb-2" type="button" data-toggle="collapse" data-target="#filter-options" aria-expanded="false" aria-controls="filter-options">
|
||||||
|
Filter Bills
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse w-100" id="filter-options">
|
||||||
|
<form action="{{ url_for('.list_bills') }}" method="post" class="p-2 border rounded bg-light">
|
||||||
|
{{ csrf_form.csrf_token }}
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="start_date" class="small">Start Date:</label>
|
||||||
|
<input type="date" id="start_date" name="start_date" class="form-control form-control-sm" value="{{ start_date if start_date else '' }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="end_date" class="small">End Date:</label>
|
||||||
|
<input type="date" id="end_date" name="end_date" class="form-control form-control-sm" value="{{ end_date if end_date else '' }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="payer" class="small">Who Paid:</label>
|
||||||
|
<select id="payer" name="payer" class="form-control form-control-sm">
|
||||||
|
<option value="">-- Select --</option>
|
||||||
|
{% for member in g.project.members %}
|
||||||
|
<option value="{{ member.id }}" {% if selected_payer == member.id %}selected{% endif %}>
|
||||||
|
{{ member.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="owers" class="small">For Whom:</label>
|
||||||
|
<select id="owers" name="owers" multiple class="form-control form-control-sm">
|
||||||
|
{% for member in g.project.members %}
|
||||||
|
<option value="{{ member.id }}" {% if selected_owers and member.id in selected_owers %}selected{% endif %}>
|
||||||
|
{{ member.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="bill_name" class="small">For What?</label>
|
||||||
|
<input type="text" id="bill_name" name="bill_name" class="form-control form-control-sm" value="{{ bill_name if bill_name else '' }}" placeholder="Enter bill name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-right">
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm">Apply Filters</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<span id="new-bill" class="ml-auto pb-2" {% if not g.project.members %} data-toggle="tooltip" title="{{_('You should start by adding participants')}}" {% endif %}>
|
<span id="new-bill" class="ml-auto pb-2" {% if not g.project.members %} data-toggle="tooltip" title="{{_('You should start by adding participants')}}" {% endif %}>
|
||||||
<a href="{{ url_for('.add_bill') }}" class="btn btn-primary {% if not g.project.members %} disabled {% endif %}" data-toggle="modal" data-keyboard="true" data-target="#bill-form" autofocus>
|
<a href="{{ url_for('.add_bill') }}" class="btn btn-primary {% if not g.project.members %} disabled {% endif %}" data-toggle="modal" data-keyboard="true" data-target="#bill-form" autofocus>
|
||||||
<i class="icon icon-white before-text">{{ static_include("images/plus.svg") | safe }}</i>
|
<i class="icon icon-white before-text">{{ static_include("images/plus.svg") | safe }}</i>
|
||||||
|
|
|
@ -649,7 +649,7 @@ def invite():
|
||||||
return render_template("send_invites.html", form=form, qrcode=qrcode_svg)
|
return render_template("send_invites.html", form=form, qrcode=qrcode_svg)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/<project_id>/")
|
@main.route("/<project_id>/", methods=["GET", "POST"])
|
||||||
def list_bills():
|
def list_bills():
|
||||||
bill_form = get_billform_for(g.project)
|
bill_form = get_billform_for(g.project)
|
||||||
# Used for CSRF validation
|
# Used for CSRF validation
|
||||||
|
@ -673,10 +673,10 @@ def list_bills():
|
||||||
# Each item will be a (weight_sum, Bill) tuple.
|
# Each item will be a (weight_sum, Bill) tuple.
|
||||||
# TODO: improve this awkward result using column_property:
|
# TODO: improve this awkward result using column_property:
|
||||||
# https://docs.sqlalchemy.org/en/14/orm/mapped_sql_expr.html.
|
# https://docs.sqlalchemy.org/en/14/orm/mapped_sql_expr.html.
|
||||||
|
if request.method == "GET":
|
||||||
weighted_bills = g.project.get_bill_weights_ordered().paginate(
|
weighted_bills = g.project.get_bill_weights_ordered().paginate(
|
||||||
per_page=100, error_out=True
|
per_page=100, error_out=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"list_bills.html",
|
"list_bills.html",
|
||||||
bills=weighted_bills,
|
bills=weighted_bills,
|
||||||
|
@ -686,6 +686,29 @@ def list_bills():
|
||||||
add_bill=request.values.get("add_bill", False),
|
add_bill=request.values.get("add_bill", False),
|
||||||
current_view="list_bills",
|
current_view="list_bills",
|
||||||
)
|
)
|
||||||
|
if request.method == "POST":
|
||||||
|
start_date = request.form['start_date']
|
||||||
|
end_date = request.form['end_date']
|
||||||
|
payer = request.form.get('payer', type=int)
|
||||||
|
owers = request.form.getlist('owers', type=int)
|
||||||
|
bill_name = request.form.get('bill_name', '').strip()
|
||||||
|
weighted_bills = g.project.get_filtered_bill_weights_ordered(start_date, end_date, payer, owers, bill_name).paginate(
|
||||||
|
per_page=100, error_out=True
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
"list_bills.html",
|
||||||
|
bills=weighted_bills,
|
||||||
|
member_form=MemberForm(g.project),
|
||||||
|
bill_form=bill_form,
|
||||||
|
csrf_form=csrf_form,
|
||||||
|
add_bill=request.values.get("add_bill", False),
|
||||||
|
current_view="list_bills",
|
||||||
|
start_date=start_date,
|
||||||
|
end_date=end_date,
|
||||||
|
selected_payer=payer,
|
||||||
|
selected_owers=owers,
|
||||||
|
bill_name=bill_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/<project_id>/members/add", methods=["GET", "POST"])
|
@main.route("/<project_id>/members/add", methods=["GET", "POST"])
|
||||||
|
|
Loading…
Reference in a new issue