Compare commits
No commits in common. "ef711f18281033b97301027bb5bc71b1e376d8d3" and "16534fc7556cce817b2c6567027eca2886dc7523" have entirely different histories.
ef711f1828
...
16534fc755
@ -49,16 +49,13 @@ def plugin_init():
|
||||
drcr.plugins.transaction_providers.append(make_tax_transactions)
|
||||
|
||||
@assert_aud
|
||||
def make_tax_transactions(start_date=None, end_date=None):
|
||||
def make_tax_transactions():
|
||||
report = tax_summary_report()
|
||||
tax_amount = report.by_id('total_tax').amount
|
||||
|
||||
# Get EOFY date
|
||||
dt = eofy_date()
|
||||
|
||||
if (start_date is not None and start_date > dt) or (end_date is not None and end_date < dt):
|
||||
return []
|
||||
|
||||
report = tax_summary_report()
|
||||
tax_amount = report.by_id('total_tax').amount - report.by_id('offsets').amount
|
||||
|
||||
# Estimated tax payable
|
||||
transactions = [Transaction(
|
||||
dt=dt,
|
||||
|
@ -241,13 +241,12 @@ class TrialBalancer:
|
||||
# First SELECT the last applicable dt by account
|
||||
# Then, among the transactions with that dt, SELECT the last applicable transaction_id
|
||||
# Then extract the running_balance for each account at that transaction_id
|
||||
# NB: We need to specify DATE(...) otherwise SQLite appears to do a string comparison which doesn't work properly with SQLAlchemy's prepared statement?
|
||||
running_balances = db.session.execute('''
|
||||
SELECT p3.account, running_balance FROM
|
||||
(
|
||||
SELECT p1.account, max(p2.transaction_id) AS max_tid FROM
|
||||
(
|
||||
SELECT account, max(dt) AS max_dt FROM postings JOIN transactions ON postings.transaction_id = transactions.id WHERE DATE(dt) < DATE(:start_date) GROUP BY account
|
||||
SELECT account, max(dt) AS max_dt FROM postings JOIN transactions ON postings.transaction_id = transactions.id WHERE dt < :start_date GROUP BY account
|
||||
) p1
|
||||
JOIN postings p2 ON p1.account = p2.account AND p1.max_dt = transactions.dt JOIN transactions ON p2.transaction_id = transactions.id GROUP BY p2.account
|
||||
) p3
|
||||
@ -283,7 +282,7 @@ class TrialBalancer:
|
||||
(
|
||||
SELECT p1.account, max(p2.transaction_id) AS max_tid FROM
|
||||
(
|
||||
SELECT account, max(dt) AS max_dt FROM postings JOIN transactions ON postings.transaction_id = transactions.id WHERE DATE(dt) <= DATE(:end_date) GROUP BY account
|
||||
SELECT account, max(dt) AS max_dt FROM postings JOIN transactions ON postings.transaction_id = transactions.id WHERE dt <= :end_date GROUP BY account
|
||||
) p1
|
||||
JOIN postings p2 ON p1.account = p2.account AND p1.max_dt = transactions.dt JOIN transactions ON p2.transaction_id = transactions.id GROUP BY p2.account
|
||||
) p3
|
||||
|
@ -22,7 +22,6 @@ from .plugins import account_kinds, advanced_reports, data_sources
|
||||
from .reports import balance_sheet_report, income_statement_report
|
||||
from .webapp import all_transactions, api_transactions, app
|
||||
|
||||
from datetime import datetime
|
||||
from itertools import groupby
|
||||
|
||||
@app.route('/')
|
||||
@ -70,10 +69,8 @@ def general_ledger():
|
||||
|
||||
@app.route('/trial-balance')
|
||||
def trial_balance():
|
||||
dt = datetime.strptime(request.args['date'], '%Y-%m-%d') if 'date' in request.args else None
|
||||
|
||||
balancer = TrialBalancer.from_cached(end_date=dt)
|
||||
balancer.apply_transactions(api_transactions(end_date=dt))
|
||||
balancer = TrialBalancer.from_cached()
|
||||
balancer.apply_transactions(api_transactions())
|
||||
|
||||
total_dr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity > 0), reporting_commodity())
|
||||
total_cr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity < 0), reporting_commodity())
|
||||
@ -129,13 +126,5 @@ def balance_sheet():
|
||||
|
||||
@app.route('/income-statement')
|
||||
def income_statement():
|
||||
if 'end_date' in request.args:
|
||||
start_date = datetime.strptime(request.args['start_date'], '%Y-%m-%d') if 'start_date' in request.args else datetime.min
|
||||
end_date = datetime.strptime(request.args['end_date'], '%Y-%m-%d')
|
||||
|
||||
print(end_date)
|
||||
else:
|
||||
start_date, end_date = None, None
|
||||
|
||||
report = income_statement_report(start_date=start_date, end_date=end_date)
|
||||
report = income_statement_report()
|
||||
return render_template('report.html', report=report)
|
||||
|
@ -32,29 +32,23 @@ import time
|
||||
app.config['SQLALCHEMY_RECORD_QUERIES'] = app.debug
|
||||
db.init_app(app)
|
||||
|
||||
def limit_query_dt(query, field, start_date=None, end_date=None):
|
||||
"""Helper function to limit the query between the start and end dates"""
|
||||
|
||||
if start_date and end_date:
|
||||
return query.where((field >= start_date) & (field <= end_date))
|
||||
if start_date:
|
||||
return query.where(field >= start_date)
|
||||
if end_date:
|
||||
return query.where(field <= end_date)
|
||||
return query
|
||||
|
||||
def all_transactions(start_date=None, end_date=None, join_postings=True):
|
||||
"""Return all transactions, including from DB and API"""
|
||||
|
||||
# All Transactions in database between start_date and end_date
|
||||
query = db.select(Transaction)
|
||||
query = limit_query_dt(query, Transaction.dt, start_date, end_date)
|
||||
if start_date and end_date:
|
||||
query = query.where((Transaction.dt >= start_date) & (Transaction.dt <= end_date))
|
||||
elif start_date:
|
||||
query = query.where(Transaction.dt >= start_date)
|
||||
elif end_date:
|
||||
query = query.where(Transaction.dt <= end_date)
|
||||
if join_postings:
|
||||
query = query.options(db.selectinload(Transaction.postings))
|
||||
|
||||
transactions = db.session.scalars(query).all()
|
||||
|
||||
transactions.extend(api_transactions(start_date=start_date, end_date=end_date))
|
||||
transactions.extend(api_transactions(start_date, end_date))
|
||||
|
||||
return transactions
|
||||
|
||||
@ -64,13 +58,13 @@ def api_transactions(start_date=None, end_date=None):
|
||||
transactions = []
|
||||
|
||||
# Unreconciled StatementLines
|
||||
query = db.select(StatementLine).where(StatementLine.reconciliation == None)
|
||||
query = limit_query_dt(query, StatementLine.dt, start_date, end_date)
|
||||
transactions.extend(line.into_transaction() for line in db.session.scalars(query).all())
|
||||
# FIXME: Filter by start_date and end_date
|
||||
transactions.extend(line.into_transaction() for line in StatementLine.query.filter(StatementLine.reconciliation == None))
|
||||
|
||||
# Plugins
|
||||
# FIXME: Filter by start_date and end_date
|
||||
for transaction_provider in transaction_providers:
|
||||
transactions.extend(transaction_provider(start_date=start_date, end_date=end_date))
|
||||
transactions.extend(transaction_provider())
|
||||
|
||||
return transactions
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user