Display existing statement line transaction when editing

This commit is contained in:
RunasSudo 2022-12-24 13:55:19 +11:00
parent 3debfb1122
commit ee6d91d811
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 47 additions and 20 deletions

View File

@ -62,16 +62,19 @@ def statement_line_edit_transaction():
abort(404) abort(404)
if request.method == 'GET': if request.method == 'GET':
# FIXME: Show existing transaction details if len(statement_line.postings) == 0:
return render_template('statement_line_edit_transaction.html', statement_line=statement_line) 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 # Delete existing postings
if len(statement_line.postings) > 0: if len(statement_line.postings) > 0:
for posting in statement_line.postings: 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 # Queue for deletion
db_session.delete(posting.transaction) db_session.delete(posting.transaction)

View File

@ -73,13 +73,34 @@
{% if statement_line.quantity >= 0 %}<td class="has-amount">{{ statement_line.amount().format() }}</td>{% else %}<td></td>{% endif %} {% if statement_line.quantity >= 0 %}<td class="has-amount">{{ statement_line.amount().format() }}</td>{% else %}<td></td>{% endif %}
{% if statement_line.quantity < 0 %}<td class="has-amount">{{ (statement_line.amount()|abs).format() }}</td>{% else %}<td></td>{% endif %} {% if statement_line.quantity < 0 %}<td class="has-amount">{{ (statement_line.amount()|abs).format() }}</td>{% else %}<td></td>{% endif %}
</tr> </tr>
<tr data-side="charge"> {# Charge lines #}
{# Charge line #} {% if transaction == None %}
<td></td> <tr data-side="charge">
<td></td> <td></td>
<td><i>{{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }}</i> <input type="text" name="charge-account"> <a class="text-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a></td> <td></td>
{% if statement_line.quantity < 0 %}<td class="has-amount">{{ (statement_line.amount()|abs).format() }}</td>{% else %}<td></td>{% endif %} <td><i>{{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }}</i> <input type="text" name="charge-account"> <a class="text-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a></td>
{% if statement_line.quantity >= 0 %}<td class="has-amount">{{ statement_line.amount().format() }}</td>{% else %}<td></td>{% endif %} {% if statement_line.quantity < 0 %}<td class="has-amount">{{ (statement_line.amount()|abs).format() }}</td>{% else %}<td></td>{% endif %}
{% if statement_line.quantity >= 0 %}<td class="has-amount">{{ statement_line.amount().format() }}</td>{% else %}<td></td>{% endif %}
</tr>
{% elif transaction.postings|length == 2 %}
<tr data-side="charge">
<td></td>
<td></td>
<td><i>{{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }}</i> <input type="text" name="charge-account" value="{{ transaction.charge_account(statement_line.source_account) }}"> <a class="text-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a></td>
{% if statement_line.quantity < 0 %}<td class="has-amount">{{ (statement_line.amount()|abs).format() }}</td>{% else %}<td></td>{% endif %}
{% if statement_line.quantity >= 0 %}<td class="has-amount">{{ statement_line.amount().format() }}</td>{% else %}<td></td>{% endif %}
</tr>
{% else %}
{% for posting in transaction.postings if posting.account != statement_line.source_account %}
<tr data-side="charge">
<td></td>
<td></td>
<td><i>{{ 'Cr' if statement_line.quantity >= 0 else 'Dr' }}</i> <input type="text" name="charge-account" value="{{ posting.account }}"> <a class="text-primary" href="#" onclick="addPosting(this);return false;"><i class="bi bi-plus-circle-fill"></i></a></td>
{% if statement_line.quantity < 0 %}<td class="has-amount">{{ posting.commodity }}<input type="number" name="charge-amount" step="0.01" value="{{ posting.amount().quantity_string() }}"></td>{% else %}<td></td>{% endif %}
{% if statement_line.quantity >= 0 %}<td class="has-amount">{{ posting.commodity }}<input type="number" name="charge-amount" step="0.01" value="{{ (posting.amount()|abs).quantity_string() }}"></td>{% else %}<td></td>{% endif %}
</tr>
{% endfor %}
{% endif %}
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -40,13 +40,16 @@
<td>{{ line.source_account }}</td> <td>{{ line.source_account }}</td>
<td>{{ line.dt.strftime('%Y-%m-%d') }}</td> <td>{{ line.dt.strftime('%Y-%m-%d') }}</td>
<td>{{ line.description }}</td> <td>{{ line.description }}</td>
{% if line.postings|length == 0 %} <td class="charge-account">
<td class="charge-account"><a href="#" class="text-danger" onclick="classifyLine({{ line.id }});return false;">Unclassified</a> <a href="/statement-lines/edit-transaction?line-id={{ line.id }}" class="text-muted"><i class="bi bi-pencil"></i></a></td> {% if line.postings|length == 0 %}
{% elif line.is_complex() %} <a href="#" class="text-danger" onclick="classifyLine({{ line.id }});return false;">Unclassified</a>
<td class="charge-account"><i>(Complex)</i></td> {% elif line.is_complex() %}
{% else %} <i>(Complex)</i>
<td class="charge-account"><a href="#" class="text-body" onclick="classifyLine({{ line.id }});return false;">{{ line.postings[0].transaction.charge_account(line.source_account) }}</a> <a href="/statement-lines/edit-transaction?line-id={{ line.id }}" class="text-muted"><i class="bi bi-pencil"></i></a></td> {% else %}
{% endif %} <a href="#" class="text-body" onclick="classifyLine({{ line.id }});return false;">{{ line.postings[0].transaction.charge_account(line.source_account) }}</a>
{% endif %}
<a href="/statement-lines/edit-transaction?line-id={{ line.id }}" class="text-muted"><i class="bi bi-pencil"></i></a>
</td>
<td>{{ line.amount().format() if line.quantity >= 0 else '' }}</td> <td>{{ line.amount().format() if line.quantity >= 0 else '' }}</td>
<td>{{ (line.amount()|abs).format() if line.quantity < 0 else '' }}</td> <td>{{ (line.amount()|abs).format() if line.quantity < 0 else '' }}</td>
<td>{{ line.balance or '' }}</td> <td>{{ line.balance or '' }}</td>