From 474e844ed95cab2390fe15519007b5813a2ac4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 28 Feb 2023 21:35:02 +0800 Subject: [PATCH] Revised the loading of the summary helper so that only the required helpers are loaded, but not both the debit and credit helpers. --- .../accounting/transaction/expense/include/form.html | 3 +++ .../templates/accounting/transaction/include/form.html | 3 --- .../accounting/transaction/income/include/form.html | 3 +++ .../accounting/transaction/transfer/include/form.html | 6 ++++++ src/accounting/transaction/summary_helper.py | 4 +--- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/accounting/templates/accounting/transaction/expense/include/form.html b/src/accounting/templates/accounting/transaction/expense/include/form.html index e197822..da106f3 100644 --- a/src/accounting/templates/accounting/transaction/expense/include/form.html +++ b/src/accounting/templates/accounting/transaction/expense/include/form.html @@ -46,5 +46,8 @@ First written: 2023/2/25 {% endblock %} {% block account_selector_modals %} + {% with summary_helper = form.summary_helper.debit %} + {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% endwith %} {% include "accounting/transaction/include/debit-account-modal.html" %} {% endblock %} diff --git a/src/accounting/templates/accounting/transaction/include/form.html b/src/accounting/templates/accounting/transaction/include/form.html index f25fd9c..d89a091 100644 --- a/src/accounting/templates/accounting/transaction/include/form.html +++ b/src/accounting/templates/accounting/transaction/include/form.html @@ -86,9 +86,6 @@ First written: 2023/2/26 {% include "accounting/transaction/include/entry-form-modal.html" %} -{% for summary_helper in form.summary_helper.types %} - {% include "accounting/transaction/include/summary-helper-modal.html" %} -{% endfor %} {% block account_selector_modals %}{% endblock %} {% endblock %} diff --git a/src/accounting/templates/accounting/transaction/income/include/form.html b/src/accounting/templates/accounting/transaction/income/include/form.html index 2be8fb2..73a9bdc 100644 --- a/src/accounting/templates/accounting/transaction/income/include/form.html +++ b/src/accounting/templates/accounting/transaction/income/include/form.html @@ -46,5 +46,8 @@ First written: 2023/2/25 {% endblock %} {% block account_selector_modals %} + {% with summary_helper = form.summary_helper.credit %} + {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% endwith %} {% include "accounting/transaction/include/credit-account-modal.html" %} {% endblock %} diff --git a/src/accounting/templates/accounting/transaction/transfer/include/form.html b/src/accounting/templates/accounting/transaction/transfer/include/form.html index 941c091..fad2b00 100644 --- a/src/accounting/templates/accounting/transaction/transfer/include/form.html +++ b/src/accounting/templates/accounting/transaction/transfer/include/form.html @@ -50,6 +50,12 @@ First written: 2023/2/25 {% endblock %} {% block account_selector_modals %} + {% with summary_helper = form.summary_helper.debit %} + {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% endwith %} + {% with summary_helper = form.summary_helper.credit %} + {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% endwith %} {% include "accounting/transaction/include/debit-account-modal.html" %} {% include "accounting/transaction/include/credit-account-modal.html" %} {% endblock %} diff --git a/src/accounting/transaction/summary_helper.py b/src/accounting/transaction/summary_helper.py index 5805a62..9d5181e 100644 --- a/src/accounting/transaction/summary_helper.py +++ b/src/accounting/transaction/summary_helper.py @@ -206,8 +206,6 @@ class SummaryHelper: """The debit tags.""" self.credit: SummaryEntryType = SummaryEntryType("credit") """The credit tags.""" - self.types: set[SummaryEntryType] = {self.debit, self.credit} - """The tags categorized by the entry types.""" entry_type: sa.Label = sa.case((JournalEntry.is_debit, "debit"), else_="credit").label("entry_type") tag_type: sa.Label = sa.case( @@ -227,7 +225,7 @@ class SummaryHelper: = {x.id: x for x in Account.query .filter(Account.id.in_({x.account_id for x in result})).all()} entry_type_dict: dict[t.Literal["debit", "credit"], SummaryEntryType] \ - = {x.type: x for x in self.types} + = {x.type: x for x in {self.debit, self.credit}} for row in result: entry_type_dict[row.entry_type].add_tag( row.tag_type, row.tag, accounts[row.account_id], row.freq)