austax: Automatically hide non-applicable sections from tax summary report
This commit is contained in:
parent
ad5571e219
commit
a8966cc19e
@ -84,22 +84,26 @@ def tax_summary_report():
|
||||
entries=[
|
||||
Section(
|
||||
title='Salary or wages (1)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income1', neg=True, floor=100) + [Subtotal('Total item 1', id='income1')]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income1', neg=True, floor=100) + [Subtotal('Total item 1', id='income1')],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Section(
|
||||
title='Australian Government allowances and payments (5)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income5', neg=True) + [Subtotal('Total item 5', id='income5', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income5', neg=True) + [Subtotal('Total item 5', id='income5', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Section(
|
||||
title='Gross interest (10)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income10', neg=True) + [Subtotal('Total item 10', id='income10', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income10', neg=True) + [Subtotal('Total item 10', id='income10', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Section(
|
||||
title='Partnerships and trusts (13)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income13', neg=True, floor=100) + [Subtotal('Total item 13', id='income13', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income13', neg=True, floor=100) + [Subtotal('Total item 13', id='income13', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
#Section(
|
||||
@ -109,7 +113,8 @@ def tax_summary_report():
|
||||
#Spacer(),
|
||||
Section(
|
||||
title='Foreign source income and foreign assets or property (20)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income20', neg=True, floor=100) + [Subtotal('Total item 20', id='income20', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.income20', neg=True, floor=100) + [Subtotal('Total item 20', id='income20', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Calculated(
|
||||
@ -122,22 +127,26 @@ def tax_summary_report():
|
||||
Spacer(),
|
||||
Section(
|
||||
title='Work-related travel expenses (D2)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d2') + [Subtotal('Total item D2', id='d2', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d2') + [Subtotal('Total item D2', id='d2', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Section(
|
||||
title='Work-related self-education expenses (D4)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d4') + [Subtotal('Total item D4', id='d4', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d4') + [Subtotal('Total item D4', id='d4', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Section(
|
||||
title='Other work-related expenses (D5)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d5') + [Subtotal('Total item D5', id='d5', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d5') + [Subtotal('Total item D5', id='d5', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Section(
|
||||
title='Gifts or donations (D9)',
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d9') + [Subtotal('Total item D9', id='d9', floor=100)]
|
||||
entries=entries_for_kind(account_configurations, accounts, 'austax.d9') + [Subtotal('Total item D9', id='d9', floor=100)],
|
||||
auto_hide=True
|
||||
),
|
||||
Spacer(),
|
||||
Calculated(
|
||||
|
@ -46,15 +46,28 @@ class Report:
|
||||
return None
|
||||
|
||||
class Section:
|
||||
def __init__(self, title=None, entries=None, *, id=None):
|
||||
def __init__(self, title=None, entries=None, *, id=None, visible=True, auto_hide=False):
|
||||
self.title = title
|
||||
self.entries = entries or []
|
||||
self.id = id
|
||||
self.visible = visible
|
||||
self.auto_hide = auto_hide
|
||||
|
||||
def calculate(self, parent):
|
||||
for entry in self.entries:
|
||||
entry.calculate(self)
|
||||
|
||||
if self.auto_hide and self.visible:
|
||||
if not any(isinstance(e, Entry) for e in self.entries):
|
||||
# Auto hide if no entries (other than Subtotal)
|
||||
self.visible = False
|
||||
|
||||
# Hide next Spacer
|
||||
idx = parent.entries.index(self)
|
||||
if idx + 1 < len(parent.entries):
|
||||
if isinstance(parent.entries[idx + 1], Spacer):
|
||||
parent.entries[idx + 1].visible = False
|
||||
|
||||
def by_id(self, id):
|
||||
# TODO: Make more efficient?
|
||||
|
||||
@ -69,10 +82,11 @@ class Section:
|
||||
return None
|
||||
|
||||
class Entry:
|
||||
def __init__(self, text=None, amount=None, *, id=None, link=None, heading=False, bordered=False):
|
||||
def __init__(self, text=None, amount=None, *, id=None, visible=True, link=None, heading=False, bordered=False):
|
||||
self.text = text
|
||||
self.amount = amount
|
||||
self.id = id
|
||||
self.visible = visible
|
||||
self.link = link
|
||||
self.heading = heading
|
||||
self.bordered = bordered
|
||||
@ -110,6 +124,9 @@ class Calculated(Entry):
|
||||
class Spacer:
|
||||
id = None
|
||||
|
||||
def __init__(self, *, visible=True):
|
||||
self.visible = visible
|
||||
|
||||
def calculate(self, parent):
|
||||
pass
|
||||
|
||||
|
@ -31,15 +31,14 @@
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_entry(entry) %}
|
||||
{% if entry.visible %}
|
||||
{% if entry.__class__.__name__ == 'Section' %}
|
||||
{{ render_section(entry) }}
|
||||
{% elif entry.__class__.__name__ == 'Subtotal' %}
|
||||
{% if entry.visible %}
|
||||
<tr{% if entry.bordered %} style="border-width:1px 0"{% endif %}>
|
||||
<th>{{ entry.text }}</th>
|
||||
<th class="text-end">{{ entry.amount.format_accounting() }}</th>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% elif entry.__class__.__name__ == 'Spacer' %}
|
||||
<tr><td colspan="2"> </td></tr>
|
||||
{% else %}
|
||||
@ -54,6 +53,7 @@
|
||||
<{{ 'th' if entry.heading else 'td' }} class="text-end">{{ entry.amount.format_accounting() }}</{{ 'th' if entry.heading else 'td' }}>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
|
Loading…
Reference in New Issue
Block a user