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=[
|
entries=[
|
||||||
Section(
|
Section(
|
||||||
title='Salary or wages (1)',
|
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(),
|
Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Australian Government allowances and payments (5)',
|
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(),
|
Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Gross interest (10)',
|
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(),
|
Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Partnerships and trusts (13)',
|
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(),
|
Spacer(),
|
||||||
#Section(
|
#Section(
|
||||||
@ -109,7 +113,8 @@ def tax_summary_report():
|
|||||||
#Spacer(),
|
#Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Foreign source income and foreign assets or property (20)',
|
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(),
|
Spacer(),
|
||||||
Calculated(
|
Calculated(
|
||||||
@ -122,22 +127,26 @@ def tax_summary_report():
|
|||||||
Spacer(),
|
Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Work-related travel expenses (D2)',
|
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(),
|
Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Work-related self-education expenses (D4)',
|
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(),
|
Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Other work-related expenses (D5)',
|
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(),
|
Spacer(),
|
||||||
Section(
|
Section(
|
||||||
title='Gifts or donations (D9)',
|
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(),
|
Spacer(),
|
||||||
Calculated(
|
Calculated(
|
||||||
|
@ -46,14 +46,27 @@ class Report:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
class Section:
|
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.title = title
|
||||||
self.entries = entries or []
|
self.entries = entries or []
|
||||||
self.id = id
|
self.id = id
|
||||||
|
self.visible = visible
|
||||||
|
self.auto_hide = auto_hide
|
||||||
|
|
||||||
def calculate(self, parent):
|
def calculate(self, parent):
|
||||||
for entry in self.entries:
|
for entry in self.entries:
|
||||||
entry.calculate(self)
|
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):
|
def by_id(self, id):
|
||||||
# TODO: Make more efficient?
|
# TODO: Make more efficient?
|
||||||
@ -69,10 +82,11 @@ class Section:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
class Entry:
|
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.text = text
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
self.id = id
|
self.id = id
|
||||||
|
self.visible = visible
|
||||||
self.link = link
|
self.link = link
|
||||||
self.heading = heading
|
self.heading = heading
|
||||||
self.bordered = bordered
|
self.bordered = bordered
|
||||||
@ -110,6 +124,9 @@ class Calculated(Entry):
|
|||||||
class Spacer:
|
class Spacer:
|
||||||
id = None
|
id = None
|
||||||
|
|
||||||
|
def __init__(self, *, visible=True):
|
||||||
|
self.visible = visible
|
||||||
|
|
||||||
def calculate(self, parent):
|
def calculate(self, parent):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -31,28 +31,28 @@
|
|||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro render_entry(entry) %}
|
{% macro render_entry(entry) %}
|
||||||
{% if entry.__class__.__name__ == 'Section' %}
|
{% if entry.visible %}
|
||||||
{{ render_section(entry) }}
|
{% if entry.__class__.__name__ == 'Section' %}
|
||||||
{% elif entry.__class__.__name__ == 'Subtotal' %}
|
{{ render_section(entry) }}
|
||||||
{% if entry.visible %}
|
{% elif entry.__class__.__name__ == 'Subtotal' %}
|
||||||
<tr{% if entry.bordered %} style="border-width:1px 0"{% endif %}>
|
<tr{% if entry.bordered %} style="border-width:1px 0"{% endif %}>
|
||||||
<th>{{ entry.text }}</th>
|
<th>{{ entry.text }}</th>
|
||||||
<th class="text-end">{{ entry.amount.format_accounting() }}</th>
|
<th class="text-end">{{ entry.amount.format_accounting() }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% elif entry.__class__.__name__ == 'Spacer' %}
|
||||||
|
<tr><td colspan="2"> </td></tr>
|
||||||
|
{% else %}
|
||||||
|
<tr{% if entry.bordered %} style="border-width:1px 0"{% endif %}>
|
||||||
|
<{{ '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' }}>
|
||||||
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif entry.__class__.__name__ == 'Spacer' %}
|
|
||||||
<tr><td colspan="2"> </td></tr>
|
|
||||||
{% else %}
|
|
||||||
<tr{% if entry.bordered %} style="border-width:1px 0"{% endif %}>
|
|
||||||
<{{ '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' }}>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user