From 4aa6c610e43d3a3c87deb9f71ff1f7baa2d6a8cc Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 29 Jan 2023 19:18:30 +1100 Subject: [PATCH] Re-implement statement lines "Reconcile selected as transfer" --- drcr/statements/views.py | 26 +++++++++++++------ .../templates/statements/statement_lines.html | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/drcr/statements/views.py b/drcr/statements/views.py index 8c51e5a..42808cb 100644 --- a/drcr/statements/views.py +++ b/drcr/statements/views.py @@ -139,19 +139,29 @@ def statement_line_reconcile_transfer(): if line1.quantity != -line2.quantity or line1.commodity != line2.commodity: raise Exception('Selected statement line debits/credits must equal') - # Delete existing postings - line1.delete_postings() - line2.delete_postings() + if line1.reconciliation or line2.reconciliation: + raise Exception('NYI') - transaction = StatementLineTransaction( + # Create transaction + posting1 = Posting(account=line1.source_account, quantity=line1.quantity, commodity=line1.commodity) + posting2 = Posting(account=line2.source_account, quantity=line2.quantity, commodity=line2.commodity) + transaction = Transaction( dt=line1.dt, description=line1.description, - postings=[ - StatementLinePosting(statement_line=line1, description=line1.description, account=line1.source_account, quantity=line1.quantity, commodity=line1.commodity), - StatementLinePosting(statement_line=line2, description=line2.description, account=line2.source_account, quantity=line2.quantity, commodity=line2.commodity) - ] + postings=[posting1, posting2] ) db.session.add(transaction) + + # Reconcile statement lines + db.session.add(StatementLineReconciliation( + statement_line=line1, + posting=posting1 + )) + db.session.add(StatementLineReconciliation( + statement_line=line2, + posting=posting2 + )) + db.session.commit() return redirect(url_for('statement_lines')) diff --git a/drcr/templates/statements/statement_lines.html b/drcr/templates/statements/statement_lines.html index 9cf1cca..34e2a94 100644 --- a/drcr/templates/statements/statement_lines.html +++ b/drcr/templates/statements/statement_lines.html @@ -23,8 +23,8 @@
- {##}
+ Import statement