Re-implement charging statement lines for consolidated Transaction model

This commit is contained in:
RunasSudo 2023-01-02 18:57:25 +11:00
parent 33cf00ecec
commit 3c661100e5
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 19 additions and 9 deletions

View File

@ -18,8 +18,9 @@ from flask import abort, redirect, render_template, request
from .. import AMOUNT_DPS
from ..database import db
from ..models import Posting, Transaction
from ..webapp import app
from .models import StatementLine
from .models import StatementLine, StatementLineReconciliation
@app.route('/statement-lines')
def statement_lines():
@ -36,19 +37,26 @@ def statement_line_charge():
if not statement_line:
abort(404)
# Delete existing postings
statement_line.delete_postings()
if statement_line.reconciliation:
raise Exception('NYI')
transaction = StatementLineTransaction(
# Create transaction
posting_source = Posting(account=statement_line.source_account, quantity=statement_line.quantity, commodity=statement_line.commodity)
posting_charge = Posting(account=request.form['charge-account'], quantity=-statement_line.quantity, commodity=statement_line.commodity)
transaction = Transaction(
dt=statement_line.dt,
description=statement_line.description,
postings=[
StatementLinePosting(statement_line=statement_line, account=statement_line.source_account, quantity=statement_line.quantity, commodity=statement_line.commodity),
StatementLinePosting(account=request.form['charge-account'], quantity=-statement_line.quantity, commodity=statement_line.commodity)
]
postings=[posting_source, posting_charge]
)
db.session.add(transaction)
# Reconcile statement line
reconciliation = StatementLineReconciliation(
statement_line=statement_line,
posting=posting_source
)
db.session.add(reconciliation)
db.session.commit()
return 'OK'

View File

@ -84,6 +84,8 @@
if (xhr.status === 200) {
document.querySelector('[data-line-id="' + lineId + '"] .charge-account a').innerText = chargeAccount;
document.querySelector('[data-line-id="' + lineId + '"] .charge-account a').className = 'text-body';
} else {
alert('Error when charging statement line');
}
});
xhr.open('POST', '/statement-lines/charge');