Re-implement statement lines "Reconcile selected as transfer"

This commit is contained in:
RunasSudo 2023-01-29 19:18:30 +11:00
parent 63f37fc2a1
commit 4aa6c610e4
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 19 additions and 9 deletions

View File

@ -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'))

View File

@ -23,8 +23,8 @@
<form method="POST">
<div class="mb-2 d-flex">
{#<button type="submit" class="btn btn-outline-secondary" formaction="/statement-lines/reconcile-transfer">Reconcile selected as transfer</button>#}
<div class="flex-grow-1">
<button type="submit" class="btn btn-outline-secondary" formaction="/statement-lines/reconcile-transfer">Reconcile selected as transfer</button>
<a href="{{ url_for('statement_lines_import') }}" class="btn btn-outline-secondary">Import statement</a>
</div>
<nav class="flex-end">