[History] Add details of bills in history

This commit is contained in:
Jojo144 2023-09-01 16:31:16 +02:00
parent 11929998eb
commit 2ee2e33b64
2 changed files with 34 additions and 0 deletions

View file

@ -83,10 +83,26 @@ def get_history(project, human_readable_names=True):
"time": version.transaction.issued_at, "time": version.transaction.issued_at,
"operation_type": version.operation_type, "operation_type": version.operation_type,
"object_type": object_type, "object_type": object_type,
"bill_details": None,
"object_desc": object_str, "object_desc": object_str,
"ip": version.transaction.remote_addr, "ip": version.transaction.remote_addr,
} }
if object_type == "Bill":
if version.operation_type == Operation.INSERT or not version.previous:
detailed_version = version
else:
detailed_version = version.previous
details = {
"date": detailed_version.date,
"payer": describe_version(detailed_version.payer),
"amount": detailed_version.amount,
"owers": [describe_version(o) for o in detailed_version.owers],
"external_link": detailed_version.external_link,
"original_currency": detailed_version.original_currency,
}
common_properties["bill_details"] = details
if version.operation_type == Operation.UPDATE: if version.operation_type == Operation.UPDATE:
# Only iterate the changeset if the previous version # Only iterate the changeset if the previous version
# Was logged # Was logged

View file

@ -91,6 +91,21 @@
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% macro bill_details(details, before=False) %}
{% set owers_list_str=details.owers|localize_list|safe %}
<details class="small">
<summary>{% if before %} {{ _("Details of the bill (before the change)") }} {% else %} {{ _("Details of the bill") }} {% endif %}</summary>
{{ _("Date:") }} {{ details.date|em_surround }}.
{{ _("Payer:") }} {{ details.payer|em_surround }}.
{{ _("Amount:") }} {{ details.amount|currency(details.original_currency)|em_surround }}.
{{ _("Owers:") }} {{ owers_list_str }}.
{% if details.external_link %}
{{ _("External link:") }}
<a class="truncated" href="{{ details.external_link }}">{{ details.external_link }}</a>
{% endif %}
</details>
{% endmacro %}
{% block sidebar %} {% block sidebar %}
<div id="table_overflow"> <div id="table_overflow">
{{ balance_table(show_weight=False, show_header=True) }} {{ balance_table(show_weight=False, show_header=True) }}
@ -177,6 +192,7 @@
{% trans %}Project {{ name }} added{% endtrans %} {% trans %}Project {{ name }} added{% endtrans %}
{% elif event.object_type == "Bill" %} {% elif event.object_type == "Bill" %}
{% trans %}Bill {{ name }} added{% endtrans %} {% trans %}Bill {{ name }} added{% endtrans %}
{{ bill_details(event.bill_details) }}
{% elif event.object_type == "Person" %} {% elif event.object_type == "Person" %}
{% trans %}Participant {{ name }} added{% endtrans %} {% trans %}Participant {{ name }} added{% endtrans %}
@ -220,6 +236,7 @@
{% else %} {% else %}
{% trans %}Bill {{ name }} modified{% endtrans %} {% trans %}Bill {{ name }} modified{% endtrans %}
{% endif %} {% endif %}
{{ bill_details(event.bill_details, before=True) }}
{% elif event.object_type == "Person" %} {% elif event.object_type == "Person" %}
{% if event.prop_changed == "activated" %} {% if event.prop_changed == "activated" %}
@ -243,6 +260,7 @@
{% elif event.operation_type == OperationType.DELETE %} {% elif event.operation_type == OperationType.DELETE %}
{% if event.object_type == "Bill" %} {% if event.object_type == "Bill" %}
{% trans %}Bill {{ name }} removed{% endtrans %} {% trans %}Bill {{ name }} removed{% endtrans %}
{{ bill_details(event.bill_details) }}
{% elif event.object_type == "Person" %} {% elif event.object_type == "Person" %}
{% trans %}Participant {{ name }} removed{% endtrans %} {% trans %}Participant {{ name }} removed{% endtrans %}
{% endif %} {% endif %}