From ee6d91d811c0169508f38ed691f493530ec5e00c Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sat, 24 Dec 2022 13:55:19 +1100 Subject: [PATCH] Display existing statement line transaction when editing --- drcr/statements/views.py | 15 ++++---- .../statement_line_edit_transaction.html | 35 +++++++++++++++---- drcr/templates/statement_lines.html | 17 +++++---- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/drcr/statements/views.py b/drcr/statements/views.py index e08bf53..1019580 100644 --- a/drcr/statements/views.py +++ b/drcr/statements/views.py @@ -62,16 +62,19 @@ def statement_line_edit_transaction(): abort(404) if request.method == 'GET': - # FIXME: Show existing transaction details - return render_template('statement_line_edit_transaction.html', statement_line=statement_line) + if len(statement_line.postings) == 0: + return render_template('statement_line_edit_transaction.html', statement_line=statement_line, transaction=None) + + if len(statement_line.postings) > 1: + # NYI + raise Exception('Cannot display a StatementLine with >2 postings') + + # Get existing transaction + return render_template('statement_line_edit_transaction.html', statement_line=statement_line, transaction=statement_line.postings[0].transaction) # Delete existing postings if len(statement_line.postings) > 0: for posting in statement_line.postings: - if len(posting.transaction.postings) > 2: - # Complex posting - raise Exception('Cannot automatically delete a StatementLineTransaction with >2 postings') - # Queue for deletion db_session.delete(posting.transaction) diff --git a/drcr/templates/statement_line_edit_transaction.html b/drcr/templates/statement_line_edit_transaction.html index 0696b7f..3459cd0 100644 --- a/drcr/templates/statement_line_edit_transaction.html +++ b/drcr/templates/statement_line_edit_transaction.html @@ -73,13 +73,34 @@ {% if statement_line.quantity >= 0 %}{{ statement_line.amount().format() }}{% else %}{% endif %} {% if statement_line.quantity < 0 %}{{ (statement_line.amount()|abs).format() }}{% else %}{% endif %} - - {# Charge line #} - - - {{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }} - {% if statement_line.quantity < 0 %}{{ (statement_line.amount()|abs).format() }}{% else %}{% endif %} - {% if statement_line.quantity >= 0 %}{{ statement_line.amount().format() }}{% else %}{% endif %} + {# Charge lines #} + {% if transaction == None %} + + + + {{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }} + {% if statement_line.quantity < 0 %}{{ (statement_line.amount()|abs).format() }}{% else %}{% endif %} + {% if statement_line.quantity >= 0 %}{{ statement_line.amount().format() }}{% else %}{% endif %} + + {% elif transaction.postings|length == 2 %} + + + + {{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }} + {% if statement_line.quantity < 0 %}{{ (statement_line.amount()|abs).format() }}{% else %}{% endif %} + {% if statement_line.quantity >= 0 %}{{ statement_line.amount().format() }}{% else %}{% endif %} + + {% else %} + {% for posting in transaction.postings if posting.account != statement_line.source_account %} + + + + {{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }} + {% if statement_line.quantity < 0 %}{{ posting.commodity }}{% else %}{% endif %} + {% if statement_line.quantity >= 0 %}{{ posting.commodity }}{% else %}{% endif %} + + {% endfor %} + {% endif %} diff --git a/drcr/templates/statement_lines.html b/drcr/templates/statement_lines.html index 679e178..f4711d2 100644 --- a/drcr/templates/statement_lines.html +++ b/drcr/templates/statement_lines.html @@ -40,13 +40,16 @@ {{ line.source_account }} {{ line.dt.strftime('%Y-%m-%d') }} {{ line.description }} - {% if line.postings|length == 0 %} - Unclassified - {% elif line.is_complex() %} - (Complex) - {% else %} - {{ line.postings[0].transaction.charge_account(line.source_account) }} - {% endif %} + + {% if line.postings|length == 0 %} + Unclassified + {% elif line.is_complex() %} + (Complex) + {% else %} + {{ line.postings[0].transaction.charge_account(line.source_account) }} + {% endif %} + + {{ line.amount().format() if line.quantity >= 0 else '' }} {{ (line.amount()|abs).format() if line.quantity < 0 else '' }} {{ line.balance or '' }}