Link to account transactions view in reports

This commit is contained in:
RunasSudo 2023-01-04 10:55:00 +11:00
parent c527442ac7
commit 8de26dedf0
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 25 additions and 33 deletions

View File

@ -65,10 +65,11 @@ class Section:
return None return None
class Entry: class Entry:
def __init__(self, text=None, amount=None, *, id=None, heading=False, bordered=False): def __init__(self, text=None, amount=None, *, id=None, link=None, heading=False, bordered=False):
self.text = text self.text = text
self.amount = amount self.amount = amount
self.id = id self.id = id
self.link = link
self.heading = heading self.heading = heading
self.bordered = bordered self.bordered = bordered
@ -90,12 +91,9 @@ class Subtotal:
) )
class Calculated(Entry): class Calculated(Entry):
def __init__(self, text=None, calc=None, *, id=None, heading=False, bordered=False): def __init__(self, text=None, calc=None, **kwargs):
self.text = text super().__init__(text=text, **kwargs)
self.calc = calc self.calc = calc
self.id = id
self.heading = heading
self.bordered = bordered
self.amount = None self.amount = None
@ -114,6 +112,13 @@ def validate_accounts(accounts, account_configurations):
if n != 1: if n != 1:
raise Exception('Account "{}" mapped to {} account types (expected 1)'.format(account, n)) raise Exception('Account "{}" mapped to {} account types (expected 1)'.format(account, n))
def entries_for_kind(account_configurations, accounts, kind, neg=False):
return [
Entry(text=account_name, amount=-amount if neg else amount, link='/account-transactions?account=' + account_name)
for account_name, amount in accounts.items()
if kind in account_configurations.get(account_name, []) and amount.quantity != 0
]
def balance_sheet_report(): def balance_sheet_report():
# Get trial balance # Get trial balance
balancer = TrialBalancer() balancer = TrialBalancer()
@ -130,32 +135,21 @@ def balance_sheet_report():
entries=[ entries=[
Section( Section(
title='Assets', title='Assets',
entries=[ entries=entries_for_kind(account_configurations, accounts, 'drcr.asset') + [Subtotal('Total assets', bordered=True)]
Entry(text=account_name, amount=amount)
for account_name, amount in accounts.items()
if 'drcr.asset' in account_configurations.get(account_name, [])
] + [Subtotal('Total assets', bordered=True)]
), ),
Spacer(), Spacer(),
Section( Section(
title='Liabilities', title='Liabilities',
entries=[ entries=entries_for_kind(account_configurations, accounts, 'drcr.liability', True) + [Subtotal('Total liabilities', bordered=True)]
Entry(text=account_name, amount=-amount)
for account_name, amount in accounts.items()
if 'drcr.liability' in account_configurations.get(account_name, [])
] + [Subtotal('Total liabilities', bordered=True)]
), ),
Spacer(), Spacer(),
Section( Section(
title='Equity', title='Equity',
entries=[ entries=entries_for_kind(account_configurations, accounts, 'drcr.equity', True) + [
Entry(text=account_name, amount=-amount)
for account_name, amount in accounts.items()
if 'drcr.equity' in account_configurations.get(account_name, [])
] + [
Calculated( Calculated(
'Current year surplus (deficit)', 'Current year surplus (deficit)',
lambda _: income_statement_report().by_id('net_surplus').amount lambda _: income_statement_report().by_id('net_surplus').amount,
link='/income-statement'
), ),
Subtotal('Total equity', bordered=True) Subtotal('Total equity', bordered=True)
] ]
@ -182,20 +176,12 @@ def income_statement_report():
entries=[ entries=[
Section( Section(
title='Income', title='Income',
entries=[ entries=entries_for_kind(account_configurations, accounts, 'drcr.income', True) + [Subtotal('Total income', id='total_income', bordered=True)]
Entry(text=account_name, amount=-amount)
for account_name, amount in accounts.items()
if 'drcr.income' in account_configurations.get(account_name, [])
] + [Subtotal('Total income', id='total_income', bordered=True)]
), ),
Spacer(), Spacer(),
Section( Section(
title='Expenses', title='Expenses',
entries=[ entries=entries_for_kind(account_configurations, accounts, 'drcr.expense') + [Subtotal('Total expenses', id='total_expenses', bordered=True)]
Entry(text=account_name, amount=amount)
for account_name, amount in accounts.items()
if 'drcr.expense' in account_configurations.get(account_name, [])
] + [Subtotal('Total expenses', id='total_expenses', bordered=True)]
), ),
Spacer(), Spacer(),
Calculated( Calculated(

View File

@ -40,7 +40,13 @@
<tr><td colspan="2">&nbsp;</td></tr> <tr><td colspan="2">&nbsp;</td></tr>
{% else %} {% else %}
<tr{% if entry.bordered %} style="border-width:1px 0"{% endif %}> <tr{% if entry.bordered %} style="border-width:1px 0"{% endif %}>
<{{ 'th' if entry.heading else 'td' }}>{{ entry.text }}</{{ 'th' if entry.heading else 'td' }}> <{{ 'th' if entry.heading else 'td' }}>
{% if entry.link %}
<a href="{{ entry.link }}">{{ entry.text }}</a>
{% else %}
{{ entry.text }}
{% endif %}
</{{ 'th' if entry.heading else 'td' }}>
<{{ 'th' if entry.heading else 'td' }} class="text-end">{{ entry.amount.format_accounting() }}</{{ 'th' if entry.heading else 'td' }}> <{{ 'th' if entry.heading else 'td' }} class="text-end">{{ entry.amount.format_accounting() }}</{{ 'th' if entry.heading else 'td' }}>
</tr> </tr>
{% endif %} {% endif %}