From 99d3d6d22dd247dea540425e10b3b64f1e9235a8 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Mon, 3 Jul 2023 22:31:58 +1000 Subject: [PATCH] Configure EOFY date in database --- austax/reports.py | 13 +++---------- drcr/models.py | 12 ++++++++++++ drcr/webapp.py | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/austax/reports.py b/austax/reports.py index 1c91679..8e0398a 100644 --- a/austax/reports.py +++ b/austax/reports.py @@ -16,24 +16,17 @@ from drcr import AMOUNT_DPS from drcr.database import db -from drcr.models import AccountConfiguration, Amount, Transaction, TrialBalancer +from drcr.models import AccountConfiguration, Amount, Metadata, Transaction, TrialBalancer from drcr.reports import Calculated, Report, Section, Spacer, Subtotal, entries_for_kind from .tax_tables import base_tax, repayment_rates, fbt_grossup from datetime import datetime -def eofy_date(dt=None): +def eofy_date(): """Get the datetime for the end of the financial year""" - if dt is None: - dt = datetime.now() - - dt_eofy = dt.replace(month=6, day=30) - if dt_eofy < dt: - dt_eofy = dt_eofy.replace(year=dt.year + 1) - - return dt_eofy + return datetime.strptime(Metadata.get('eofy_date'), '%Y-%m-%d') def base_income_tax(year, taxable_income): """Get the amount of base income tax""" diff --git a/drcr/models.py b/drcr/models.py index a6057db..df47ce2 100644 --- a/drcr/models.py +++ b/drcr/models.py @@ -237,3 +237,15 @@ class AccountConfiguration(db.Model): kinds = {k: [vv.kind for vv in v] for k, v in account_configurations.items()} return kinds + +class Metadata(db.Model): + __tablename__ = 'metadata' + + id = db.Column(db.Integer, primary_key=True) + + key = db.Column(db.String) + value = db.Column(db.String) + + @staticmethod + def get(key): + return Metadata.query.filter_by(key=key).one().value diff --git a/drcr/webapp.py b/drcr/webapp.py index 0115d8a..7fb2255 100644 --- a/drcr/webapp.py +++ b/drcr/webapp.py @@ -56,6 +56,8 @@ init_plugins() @app.cli.command('initdb') def initdb(): db.create_all() + + # FIXME: Need to init metadata if app.debug: @app.before_request