austax: Hide irrelevant reports

This commit is contained in:
RunasSudo 2024-08-16 22:40:44 +10:00
parent d50b6a0e0a
commit 3542d80483
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 25 additions and 12 deletions

View File

@ -201,11 +201,13 @@ def tax_summary_report():
), ),
Calculated( Calculated(
'Medicare levy', 'Medicare levy',
lambda _: medicare_levy(eofy_date().year, report.by_id('taxable').amount) lambda _: medicare_levy(eofy_date().year, report.by_id('taxable').amount),
auto_hide=True
), ),
Calculated( Calculated(
'Medicare levy surcharge', 'Medicare levy surcharge',
lambda _: medicare_levy_surcharge(eofy_date().year, report.by_id('taxable').amount, report.by_id('rfb_grossedup').amount) lambda _: medicare_levy_surcharge(eofy_date().year, report.by_id('taxable').amount, report.by_id('rfb_grossedup').amount),
auto_hide=True
), ),
Subtotal('Total income tax', id='total_tax', bordered=True) Subtotal('Total income tax', id='total_tax', bordered=True)
] ]
@ -214,33 +216,39 @@ def tax_summary_report():
Section( Section(
title='Tax offsets', title='Tax offsets',
entries=entries_for_kind(account_configurations, accounts, 'austax.offset', neg=True) + [ entries=entries_for_kind(account_configurations, accounts, 'austax.offset', neg=True) + [
Calculated('Low income tax offset', lambda _: lito(report.by_id('taxable').amount, report.by_id('total_tax').amount)), Calculated('Low income tax offset', lambda _: lito(report.by_id('taxable').amount, report.by_id('total_tax').amount), auto_hide=True),
Subtotal('Total tax offsets', id='offsets') Subtotal('Total tax offsets', id='offsets')
] ],
auto_hide=True
), ),
Spacer(), Spacer(),
Section( Section(
entries=[ entries=[
Calculated( Calculated(
'Taxable value of reportable fringe benefits', 'Taxable value of reportable fringe benefits',
lambda _: report.by_id('rfb_taxable').amount lambda _: report.by_id('rfb_taxable').amount,
auto_hide=True
), ),
Calculated( Calculated(
'Grossed-up value', 'Grossed-up value',
lambda _: report.by_id('rfb_grossedup').amount lambda _: report.by_id('rfb_grossedup').amount,
auto_hide=True
), ),
Calculated( Calculated(
'Mandatory study loan repayment', 'Mandatory study loan repayment',
lambda _: study_loan_repayment(eofy_date().year, report.by_id('taxable').amount, report.by_id('rfb_grossedup').amount), lambda _: study_loan_repayment(eofy_date().year, report.by_id('taxable').amount, report.by_id('rfb_grossedup').amount),
id='loan_repayment', id='loan_repayment',
heading=True heading=True,
auto_hide=True
) )
] ],
auto_hide=True
), ),
Spacer(), Spacer(),
Section( Section(
title='PAYG withheld amounts', title='PAYG withheld amounts',
entries=entries_for_kind(account_configurations, accounts, 'austax.paygw') + [Subtotal('Total withheld amounts', id='paygw')] entries=entries_for_kind(account_configurations, accounts, 'austax.paygw') + [Subtotal('Total withheld amounts', id='paygw')],
auto_hide=True
), ),
Spacer(), Spacer(),
Calculated( Calculated(

View File

@ -58,8 +58,8 @@ class Section:
entry.calculate(self) entry.calculate(self)
if self.auto_hide and self.visible: if self.auto_hide and self.visible:
if not any(isinstance(e, Entry) for e in self.entries): if not any(isinstance(e, Entry) and e.visible for e in self.entries):
# Auto hide if no entries (other than Subtotal) # Auto hide if no visible entries (other than Subtotal)
self.visible = False self.visible = False
# Hide next Spacer # Hide next Spacer
@ -82,11 +82,12 @@ class Section:
return None return None
class Entry: class Entry:
def __init__(self, text=None, amount=None, *, id=None, visible=True, link=None, heading=False, bordered=False): def __init__(self, text=None, amount=None, *, id=None, visible=True, auto_hide=False, 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.visible = visible
self.auto_hide = auto_hide
self.link = link self.link = link
self.heading = heading self.heading = heading
self.bordered = bordered self.bordered = bordered
@ -121,6 +122,10 @@ class Calculated(Entry):
def calculate(self, parent): def calculate(self, parent):
self.amount = self.calc(parent) self.amount = self.calc(parent)
if self.auto_hide and self.visible:
if self.amount.quantity == 0:
self.visible = False
class Spacer: class Spacer:
id = None id = None