Skip to content

Commit

Permalink
[History] Add details of bills in history
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojo144 committed Oct 1, 2023
1 parent 1192999 commit 2ee2e33
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ihatemoney/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,26 @@ def get_history(project, human_readable_names=True):
"time": version.transaction.issued_at,
"operation_type": version.operation_type,
"object_type": object_type,
"bill_details": None,
"object_desc": object_str,
"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:
# Only iterate the changeset if the previous version
# Was logged
Expand Down
18 changes: 18 additions & 0 deletions ihatemoney/templates/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ <h3 class="modal-title">{{ _('Delete Confirmation') }}</h3>
{% endif %}
{% 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 %}
<div id="table_overflow">
{{ balance_table(show_weight=False, show_header=True) }}
Expand Down Expand Up @@ -177,6 +192,7 @@ <h3 class="modal-title">{{ _('Delete Confirmation') }}</h3>
{% trans %}Project {{ name }} added{% endtrans %}
{% elif event.object_type == "Bill" %}
{% trans %}Bill {{ name }} added{% endtrans %}
{{ bill_details(event.bill_details) }}

{% elif event.object_type == "Person" %}
{% trans %}Participant {{ name }} added{% endtrans %}
Expand Down Expand Up @@ -220,6 +236,7 @@ <h3 class="modal-title">{{ _('Delete Confirmation') }}</h3>
{% else %}
{% trans %}Bill {{ name }} modified{% endtrans %}
{% endif %}
{{ bill_details(event.bill_details, before=True) }}

{% elif event.object_type == "Person" %}
{% if event.prop_changed == "activated" %}
Expand All @@ -243,6 +260,7 @@ <h3 class="modal-title">{{ _('Delete Confirmation') }}</h3>
{% elif event.operation_type == OperationType.DELETE %}
{% if event.object_type == "Bill" %}
{% trans %}Bill {{ name }} removed{% endtrans %}
{{ bill_details(event.bill_details) }}
{% elif event.object_type == "Person" %}
{% trans %}Participant {{ name }} removed{% endtrans %}
{% endif %}
Expand Down

0 comments on commit 2ee2e33

Please sign in to comment.