Re-implement charging statement lines for consolidated Transaction model
This commit is contained in:
parent
33cf00ecec
commit
3c661100e5
@ -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'
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user