diff --git a/austax/reports.py b/austax/reports.py index efb1b04..b7051eb 100644 --- a/austax/reports.py +++ b/austax/reports.py @@ -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( diff --git a/drcr/reports.py b/drcr/reports.py index 80176ce..92d8e16 100644 --- a/drcr/reports.py +++ b/drcr/reports.py @@ -46,14 +46,27 @@ 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 diff --git a/drcr/templates/report.html b/drcr/templates/report.html index d7fa897..c982536 100644 --- a/drcr/templates/report.html +++ b/drcr/templates/report.html @@ -31,28 +31,28 @@ {% endmacro %} {% macro render_entry(entry) %} - {% if entry.__class__.__name__ == 'Section' %} - {{ render_section(entry) }} - {% elif entry.__class__.__name__ == 'Subtotal' %} - {% if entry.visible %} + {% if entry.visible %} + {% if entry.__class__.__name__ == 'Section' %} + {{ render_section(entry) }} + {% elif entry.__class__.__name__ == 'Subtotal' %} {{ entry.text }} {{ entry.amount.format_accounting() }} + {% elif entry.__class__.__name__ == 'Spacer' %} +   + {% else %} + + <{{ 'th' if entry.heading else 'td' }}> + {% if entry.link %} + {{ entry.text }} + {% else %} + {{ entry.text }} + {% endif %} + + <{{ 'th' if entry.heading else 'td' }} class="text-end">{{ entry.amount.format_accounting() }} + {% endif %} - {% elif entry.__class__.__name__ == 'Spacer' %} -   - {% else %} - - <{{ 'th' if entry.heading else 'td' }}> - {% if entry.link %} - {{ entry.text }} - {% else %} - {{ entry.text }} - {% endif %} - - <{{ 'th' if entry.heading else 'td' }} class="text-end">{{ entry.amount.format_accounting() }} - {% endif %} {% endmacro %}