From 4eb9346d8d36f183569a8d8da27310fdede1470e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 3 Mar 2023 23:24:24 +0800 Subject: [PATCH] Renamed summary helper to summary editor. --- .../{summary-helper.js => summary-editor.js} | 152 +++++++-------- src/accounting/static/js/transaction-form.js | 6 +- .../transaction/expense/include/form.html | 4 +- .../accounting/transaction/include/form.html | 2 +- .../include/summary-editor-modal.html | 181 ++++++++++++++++++ .../include/summary-helper-modal.html | 181 ------------------ .../transaction/income/include/form.html | 4 +- .../transaction/transfer/include/form.html | 8 +- src/accounting/transaction/forms.py | 10 +- .../{summary_helper.py => summary_editor.py} | 10 +- ...mmary_helper.py => test_summary_editor.py} | 120 ++++++------ 11 files changed, 339 insertions(+), 339 deletions(-) rename src/accounting/static/js/{summary-helper.js => summary-editor.js} (88%) create mode 100644 src/accounting/templates/accounting/transaction/include/summary-editor-modal.html delete mode 100644 src/accounting/templates/accounting/transaction/include/summary-helper-modal.html rename src/accounting/transaction/{summary_helper.py => summary_editor.py} (98%) rename tests/{test_summary_helper.py => test_summary_editor.py} (77%) diff --git a/src/accounting/static/js/summary-helper.js b/src/accounting/static/js/summary-editor.js similarity index 88% rename from src/accounting/static/js/summary-helper.js rename to src/accounting/static/js/summary-editor.js index 7374dd0..ad8ec36 100644 --- a/src/accounting/static/js/summary-helper.js +++ b/src/accounting/static/js/summary-editor.js @@ -1,5 +1,5 @@ /* The Mia! Accounting Flask Project - * summary-helper.js: The JavaScript for the summary helper + * summary-editor.js: The JavaScript for the summary editor */ /* Copyright (c) 2023 imacat. @@ -23,23 +23,23 @@ // Initializes the page JavaScript. document.addEventListener("DOMContentLoaded", function () { - SummaryHelper.initialize(); + SummaryEditor.initialize(); }); /** - * A summary helper. + * A summary editor. * */ -class SummaryHelper { +class SummaryEditor { /** - * The summary helper form + * The summary editor form * @type {HTMLFormElement} */ #form; /** - * The modal of the summary helper + * The modal of the summary editor * @type {HTMLFormElement} */ #modal; @@ -129,14 +129,14 @@ class SummaryHelper { tabPlanes = {}; /** - * Constructs a summary helper. + * Constructs a summary editor. * - * @param form {HTMLFormElement} the summary helper form + * @param form {HTMLFormElement} the summary editor form */ constructor(form) { this.#form = form; this.#entryType = form.dataset.entryType; - this.prefix = "accounting-summary-helper-" + form.dataset.entryType; + this.prefix = "accounting-summary-editor-" + form.dataset.entryType; this.#modal = document.getElementById(this.prefix + "-modal"); this.summary = document.getElementById(this.prefix + "-summary"); this.number = document.getElementById(this.prefix + "-number-number"); @@ -156,13 +156,13 @@ class SummaryHelper { } this.currentTab = this.tabPlanes.general; this.#initializeSuggestedAccounts(); - const helper = this; + const editor = this; this.summary.onchange = function () { - helper.#onSummaryChange(); + editor.#onSummaryChange(); }; this.#form.onsubmit = function () { - if (helper.currentTab.validate()) { - helper.#submit(); + if (editor.currentTab.validate()) { + editor.#submit(); } return false; }; @@ -212,10 +212,10 @@ class SummaryHelper { * */ #initializeSuggestedAccounts() { - const helper = this; + const editor = this; for (const accountButton of this.#accountButtons) { accountButton.onclick = function () { - helper.#selectAccount(accountButton); + editor.#selectAccount(accountButton); }; } } @@ -260,7 +260,7 @@ class SummaryHelper { } /** - * The callback when the summary helper is shown. + * The callback when the summary editor is shown. * */ #onOpen() { @@ -270,7 +270,7 @@ class SummaryHelper { } /** - * Resets the summary helper. + * Resets the summary editor. * */ #reset() { @@ -282,36 +282,36 @@ class SummaryHelper { } /** - * The summary helpers. - * @type {{debit: SummaryHelper, credit: SummaryHelper}} + * The summary editors. + * @type {{debit: SummaryEditor, credit: SummaryEditor}} */ - static #helpers = {} + static #editors = {} /** - * Initializes the summary helpers. + * Initializes the summary editors. * */ static initialize() { - const forms = Array.from(document.getElementsByClassName("accounting-summary-helper")); + const forms = Array.from(document.getElementsByClassName("accounting-summary-editor")); const entryForm = document.getElementById("accounting-entry-form"); const formSummaryControl = document.getElementById("accounting-entry-form-summary-control"); for (const form of forms) { - const helper = new SummaryHelper(form); - this.#helpers[helper.#entryType] = helper; + const editor = new SummaryEditor(form); + this.#editors[editor.#entryType] = editor; } - const helpers = this; + const editors = this; formSummaryControl.onclick = function () { - helpers.#helpers[entryForm.dataset.entryType].#onOpen(); + editors.#editors[entryForm.dataset.entryType].#onOpen(); }; } /** - * Initializes the summary helper for a new journal entry. + * Initializes the summary editor for a new journal entry. * * @param entryType {string} the entry type, either "debit" or "credit" */ static initializeNewJournalEntry(entryType) { - this.#helpers[entryType].#onOpen(); + this.#editors[entryType].#onOpen(); } } @@ -324,10 +324,10 @@ class SummaryHelper { class TabPlane { /** - * The parent summary helper - * @type {SummaryHelper} + * The parent summary editor + * @type {SummaryEditor} */ - helper; + editor; /** * The prefix of the HTML ID and classes @@ -350,11 +350,11 @@ class TabPlane { /** * Constructs a tab plane. * - * @param helper {SummaryHelper} the parent summary helper + * @param editor {SummaryEditor} the parent summary editor */ - constructor(helper) { - this.helper = helper; - this.prefix = this.helper.prefix + "-" + this.tabId(); + constructor(editor) { + this.editor = editor; + this.prefix = this.editor.prefix + "-" + this.tabId(); this.#tab = document.getElementById(this.prefix + "-tab"); this.#page = document.getElementById(this.prefix + "-page"); const tabPlane = this; @@ -399,7 +399,7 @@ class TabPlane { * */ switchToMe() { - for (const tabPlane of Object.values(this.helper.tabPlanes)) { + for (const tabPlane of Object.values(this.editor.tabPlanes)) { tabPlane.#tab.classList.remove("active") tabPlane.#tab.ariaCurrent = "false"; tabPlane.#page.classList.add("d-none"); @@ -409,7 +409,7 @@ class TabPlane { this.#tab.ariaCurrent = "page"; this.#page.classList.remove("d-none"); this.#page.ariaCurrent = "page"; - this.helper.currentTab = this; + this.editor.currentTab = this; } } @@ -442,11 +442,11 @@ class TagTabPlane extends TabPlane { /** * Constructs a tab plane. * - * @param helper {SummaryHelper} the parent summary helper + * @param editor {SummaryEditor} the parent summary editor * @override */ - constructor(helper) { - super(helper); + constructor(editor) { + super(editor); this.tag = document.getElementById(this.prefix + "-tag"); this.tagError = document.getElementById(this.prefix + "-tag-error"); // noinspection JSValidateTypes @@ -459,7 +459,7 @@ class TagTabPlane extends TabPlane { if (tagButton.dataset.value === tabPlane.tag.value) { tagButton.classList.remove("btn-outline-primary"); tagButton.classList.add("btn-primary"); - tabPlane.helper.filterSuggestedAccounts(tagButton); + tabPlane.editor.filterSuggestedAccounts(tagButton); isMatched = true; } else { tagButton.classList.remove("btn-primary"); @@ -467,7 +467,7 @@ class TagTabPlane extends TabPlane { } } if (!isMatched) { - tabPlane.helper.filterSuggestedAccounts(null); + tabPlane.editor.filterSuggestedAccounts(null); } tabPlane.updateSummary(); tabPlane.validateTag(); @@ -494,7 +494,7 @@ class TagTabPlane extends TabPlane { break; } } - this.helper.filterSuggestedAccounts(selectedTagButton); + this.editor.filterSuggestedAccounts(selectedTagButton); } /** @@ -512,7 +512,7 @@ class TagTabPlane extends TabPlane { tagButton.classList.remove("btn-outline-primary"); tagButton.classList.add("btn-primary"); tabPlane.tag.value = tagButton.dataset.value; - tabPlane.helper.filterSuggestedAccounts(tagButton); + tabPlane.editor.filterSuggestedAccounts(tagButton); tabPlane.updateSummary(); }; } @@ -589,12 +589,12 @@ class GeneralTagTab extends TagTabPlane { * @override */ updateSummary() { - const pos = this.helper.summary.value.indexOf("—"); + const pos = this.editor.summary.value.indexOf("—"); const prefix = this.tag.value === ""? "": this.tag.value + "—"; if (pos === -1) { - this.helper.summary.value = prefix + this.helper.summary.value; + this.editor.summary.value = prefix + this.editor.summary.value; } else { - this.helper.summary.value = prefix + this.helper.summary.value.substring(pos + 1); + this.editor.summary.value = prefix + this.editor.summary.value.substring(pos + 1); } } @@ -605,7 +605,7 @@ class GeneralTagTab extends TagTabPlane { * @override */ populate() { - const found = this.helper.summary.value.match(/^([^—]+)—.+?(?:×\d+)?$/); + const found = this.editor.summary.value.match(/^([^—]+)—.+?(?:×\d+)?$/); if (found === null) { return false; } @@ -614,7 +614,7 @@ class GeneralTagTab extends TagTabPlane { if (tagButton.dataset.value === this.tag.value) { tagButton.classList.remove("btn-outline-primary"); tagButton.classList.add("btn-primary"); - this.helper.filterSuggestedAccounts(tagButton); + this.editor.filterSuggestedAccounts(tagButton); } } this.switchToMe(); @@ -671,11 +671,11 @@ class GeneralTripTab extends TagTabPlane { /** * Constructs a tab plane. * - * @param helper {SummaryHelper} the parent summary helper + * @param editor {SummaryEditor} the parent summary editor * @override */ - constructor(helper) { - super(helper); + constructor(editor) { + super(editor); this.#from = document.getElementById(this.prefix + "-from"); this.#fromError = document.getElementById(this.prefix + "-from-error"); this.#to = document.getElementById(this.prefix + "-to"); @@ -727,7 +727,7 @@ class GeneralTripTab extends TagTabPlane { break; } } - this.helper.summary.value = this.tag.value + "—" + this.#from.value + direction + this.#to.value; + this.editor.summary.value = this.tag.value + "—" + this.#from.value + direction + this.#to.value; } /** @@ -761,7 +761,7 @@ class GeneralTripTab extends TagTabPlane { * @override */ populate() { - const found = this.helper.summary.value.match(/^([^—]+)—([^—→↔]+)([→↔])(.+?)(?:×\d+)?$/); + const found = this.editor.summary.value.match(/^([^—]+)—([^—→↔]+)([→↔])(.+?)(?:×\d+)?$/); if (found === null) { return false; } @@ -781,7 +781,7 @@ class GeneralTripTab extends TagTabPlane { if (tagButton.dataset.value === this.tag.value) { tagButton.classList.remove("btn-outline-primary"); tagButton.classList.add("btn-primary"); - this.helper.filterSuggestedAccounts(tagButton); + this.editor.filterSuggestedAccounts(tagButton); } } this.switchToMe(); @@ -879,11 +879,11 @@ class BusTripTab extends TagTabPlane { /** * Constructs a tab plane. * - * @param helper {SummaryHelper} the parent summary helper + * @param editor {SummaryEditor} the parent summary editor * @override */ - constructor(helper) { - super(helper); + constructor(editor) { + super(editor); this.#route = document.getElementById(this.prefix + "-route"); this.#routeError = document.getElementById(this.prefix + "-route-error"); this.#from = document.getElementById(this.prefix + "-from"); @@ -921,7 +921,7 @@ class BusTripTab extends TagTabPlane { * @override */ updateSummary() { - this.helper.summary.value = this.tag.value + "—" + this.#route.value + "—" + this.#from.value + "→" + this.#to.value; + this.editor.summary.value = this.tag.value + "—" + this.#route.value + "—" + this.#from.value + "→" + this.#to.value; } /** @@ -949,7 +949,7 @@ class BusTripTab extends TagTabPlane { * @override */ populate() { - const found = this.helper.summary.value.match(/^([^—]+)—([^—]+)—([^—→]+)→(.+?)(?:×\d+)?$/); + const found = this.editor.summary.value.match(/^([^—]+)—([^—]+)—([^—→]+)→(.+?)(?:×\d+)?$/); if (found === null) { return false; } @@ -961,7 +961,7 @@ class BusTripTab extends TagTabPlane { if (tagButton.dataset.value === this.tag.value) { tagButton.classList.remove("btn-outline-primary"); tagButton.classList.add("btn-primary"); - this.helper.filterSuggestedAccounts(tagButton); + this.editor.filterSuggestedAccounts(tagButton); break; } } @@ -1041,11 +1041,11 @@ class RegularPaymentTab extends TabPlane { /** * Constructs a tab plane. * - * @param helper {SummaryHelper} the parent summary helper + * @param editor {SummaryEditor} the parent summary editor * @override */ - constructor(helper) { - super(helper); + constructor(editor) { + super(editor); // noinspection JSValidateTypes this.#payments = Array.from(document.getElementsByClassName(this.prefix + "-payment")); } @@ -1103,19 +1103,19 @@ class NumberTab extends TabPlane { /** * Constructs a tab plane. * - * @param helper {SummaryHelper} the parent summary helper + * @param editor {SummaryEditor} the parent summary editor * @override */ - constructor(helper) { - super(helper); + constructor(editor) { + super(editor); const tabPlane = this; - this.helper.number.onchange = function () { - const found = tabPlane.helper.summary.value.match(/^(.+)×(\d+)$/); + this.editor.number.onchange = function () { + const found = tabPlane.editor.summary.value.match(/^(.+)×(\d+)$/); if (found !== null) { - tabPlane.helper.summary.value = found[1]; + tabPlane.editor.summary.value = found[1]; } - if (parseInt(tabPlane.helper.number.value) > 1) { - tabPlane.helper.summary.value = tabPlane.helper.summary.value + "×" + tabPlane.helper.number.value; + if (parseInt(tabPlane.editor.number.value) > 1) { + tabPlane.editor.summary.value = tabPlane.editor.summary.value + "×" + tabPlane.editor.number.value; } }; } @@ -1136,7 +1136,7 @@ class NumberTab extends TabPlane { * @override */ reset() { - this.helper.number.value = ""; + this.editor.number.value = ""; } /** @@ -1146,11 +1146,11 @@ class NumberTab extends TabPlane { * @override */ populate() { - const found = this.helper.summary.value.match(/^.+×(\d+)$/); + const found = this.editor.summary.value.match(/^.+×(\d+)$/); if (found === null) { - this.helper.number.value = ""; + this.editor.number.value = ""; } else { - this.helper.number.value = found[1]; + this.editor.number.value = found[1]; } return true; } diff --git a/src/accounting/static/js/transaction-form.js b/src/accounting/static/js/transaction-form.js index c7ad4de..5cf93e8 100644 --- a/src/accounting/static/js/transaction-form.js +++ b/src/accounting/static/js/transaction-form.js @@ -171,7 +171,7 @@ function initializeNewEntryButton(button) { formAccount.dataset.code = ""; formAccount.dataset.text = ""; formAccountError.innerText = ""; - formSummaryControl.dataset.bsTarget = "#accounting-summary-helper-" + button.dataset.entryType + "-modal"; + formSummaryControl.dataset.bsTarget = "#accounting-summary-editor-" + button.dataset.entryType + "-modal"; formSummaryControl.classList.remove("accounting-not-empty"); formSummaryControl.classList.remove("is-invalid"); formSummary.dataset.value = ""; @@ -181,7 +181,7 @@ function initializeNewEntryButton(button) { formAmount.classList.remove("is-invalid"); formAmountError.innerText = ""; AccountSelector.initializeJournalEntryForm(); - SummaryHelper.initializeNewJournalEntry(button.dataset.entryType); + SummaryEditor.initializeNewJournalEntry(button.dataset.entryType); }; } @@ -228,7 +228,7 @@ function initializeJournalEntry(entry) { formAccount.innerText = accountCode.dataset.text; formAccount.dataset.code = accountCode.value; formAccount.dataset.text = accountCode.dataset.text; - formSummaryControl.dataset.bsTarget = "#accounting-summary-helper-" + entry.dataset.entryType + "-modal"; + formSummaryControl.dataset.bsTarget = "#accounting-summary-editor-" + entry.dataset.entryType + "-modal"; if (summary.value === "") { formSummaryControl.classList.remove("accounting-not-empty"); } else { diff --git a/src/accounting/templates/accounting/transaction/expense/include/form.html b/src/accounting/templates/accounting/transaction/expense/include/form.html index b5f544d..35b8523 100644 --- a/src/accounting/templates/accounting/transaction/expense/include/form.html +++ b/src/accounting/templates/accounting/transaction/expense/include/form.html @@ -46,8 +46,8 @@ First written: 2023/2/25 {% endblock %} {% block form_modals %} - {% with summary_helper = form.summary_helper.debit %} - {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% with summary_editor = form.summary_editor.debit %} + {% include "accounting/transaction/include/summary-editor-modal.html" %} {% endwith %} {% with entry_type = "debit", account_options = form.debit_account_options %} diff --git a/src/accounting/templates/accounting/transaction/include/form.html b/src/accounting/templates/accounting/transaction/include/form.html index 0b8d229..6e9154c 100644 --- a/src/accounting/templates/accounting/transaction/include/form.html +++ b/src/accounting/templates/accounting/transaction/include/form.html @@ -25,7 +25,7 @@ First written: 2023/2/26 - + {% endblock %} {% block content %} diff --git a/src/accounting/templates/accounting/transaction/include/summary-editor-modal.html b/src/accounting/templates/accounting/transaction/include/summary-editor-modal.html new file mode 100644 index 0000000..d1d961b --- /dev/null +++ b/src/accounting/templates/accounting/transaction/include/summary-editor-modal.html @@ -0,0 +1,181 @@ +{# +The Mia! Accounting Flask Project +summary-editor-modal.html: The modal of the summary editor + + Copyright (c) 2023 imacat. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Author: imacat@mail.imacat.idv.tw (imacat) +First written: 2023/2/28 +#} +
+ +
diff --git a/src/accounting/templates/accounting/transaction/include/summary-helper-modal.html b/src/accounting/templates/accounting/transaction/include/summary-helper-modal.html deleted file mode 100644 index e65a302..0000000 --- a/src/accounting/templates/accounting/transaction/include/summary-helper-modal.html +++ /dev/null @@ -1,181 +0,0 @@ -{# -The Mia! Accounting Flask Project -entry-form-modal.html: The modal of the summary helper - - Copyright (c) 2023 imacat. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -Author: imacat@mail.imacat.idv.tw (imacat) -First written: 2023/2/28 -#} -
- -
diff --git a/src/accounting/templates/accounting/transaction/income/include/form.html b/src/accounting/templates/accounting/transaction/income/include/form.html index 001d8f8..285de6a 100644 --- a/src/accounting/templates/accounting/transaction/income/include/form.html +++ b/src/accounting/templates/accounting/transaction/income/include/form.html @@ -46,8 +46,8 @@ First written: 2023/2/25 {% endblock %} {% block form_modals %} - {% with summary_helper = form.summary_helper.credit %} - {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% with summary_editor = form.summary_editor.credit %} + {% include "accounting/transaction/include/summary-editor-modal.html" %} {% endwith %} {% with entry_type = "credit", account_options = form.credit_account_options %} diff --git a/src/accounting/templates/accounting/transaction/transfer/include/form.html b/src/accounting/templates/accounting/transaction/transfer/include/form.html index 731f7d3..3ce7a65 100644 --- a/src/accounting/templates/accounting/transaction/transfer/include/form.html +++ b/src/accounting/templates/accounting/transaction/transfer/include/form.html @@ -50,11 +50,11 @@ First written: 2023/2/25 {% endblock %} {% block form_modals %} - {% with summary_helper = form.summary_helper.debit %} - {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% with summary_editor = form.summary_editor.debit %} + {% include "accounting/transaction/include/summary-editor-modal.html" %} {% endwith %} - {% with summary_helper = form.summary_helper.credit %} - {% include "accounting/transaction/include/summary-helper-modal.html" %} + {% with summary_editor = form.summary_editor.credit %} + {% include "accounting/transaction/include/summary-editor-modal.html" %} {% endwith %} {% with entry_type = "debit", account_options = form.debit_account_options %} diff --git a/src/accounting/transaction/forms.py b/src/accounting/transaction/forms.py index 184a416..c830879 100644 --- a/src/accounting/transaction/forms.py +++ b/src/accounting/transaction/forms.py @@ -37,7 +37,7 @@ from accounting import db from accounting.locale import lazy_gettext from accounting.models import Transaction, Account, JournalEntry, \ TransactionCurrency, Currency -from accounting.transaction.summary_helper import SummaryHelper +from accounting.transaction.summary_editor import SummaryEditor from accounting.utils.random_id import new_id from accounting.utils.strip_text import strip_text, strip_multiline_text from accounting.utils.user import get_current_user_pk @@ -391,12 +391,12 @@ class TransactionForm(FlaskForm): if isinstance(x, str) or isinstance(x, LazyString)] @property - def summary_helper(self) -> SummaryHelper: - """Returns the summary helper. + def summary_editor(self) -> SummaryEditor: + """Returns the summary editor. - :return: The summary helper. + :return: The summary editor. """ - return SummaryHelper() + return SummaryEditor() T = t.TypeVar("T", bound=TransactionForm) diff --git a/src/accounting/transaction/summary_helper.py b/src/accounting/transaction/summary_editor.py similarity index 98% rename from src/accounting/transaction/summary_helper.py rename to src/accounting/transaction/summary_editor.py index 9d5181e..e3bf60c 100644 --- a/src/accounting/transaction/summary_helper.py +++ b/src/accounting/transaction/summary_editor.py @@ -14,7 +14,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""The summary helper. +"""The summary editor. """ import typing as t @@ -178,7 +178,7 @@ class SummaryEntryType: @property def accounts(self) -> list[SummaryAccount]: - """Returns the suggested accounts of all tags in the summary helper in + """Returns the suggested accounts of all tags in the summary editor in the entry type, in their frequency order. :return: The suggested accounts of all tags, in their frequency order. @@ -197,11 +197,11 @@ class SummaryEntryType: key=lambda x: -freq[x])] -class SummaryHelper: - """The summary helper.""" +class SummaryEditor: + """The summary editor.""" def __init__(self): - """Constructs the summary helper.""" + """Constructs the summary editor.""" self.debit: SummaryEntryType = SummaryEntryType("debit") """The debit tags.""" self.credit: SummaryEntryType = SummaryEntryType("credit") diff --git a/tests/test_summary_helper.py b/tests/test_summary_editor.py similarity index 77% rename from tests/test_summary_helper.py rename to tests/test_summary_editor.py index 8fae8bf..35a728c 100644 --- a/tests/test_summary_helper.py +++ b/tests/test_summary_editor.py @@ -14,7 +14,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""The test for the summary helper. +"""The test for the summary editor. """ import unittest @@ -29,8 +29,8 @@ from testlib import get_client from testlib_txn import Accounts, NEXT_URI, add_txn -class SummeryHelperTestCase(unittest.TestCase): - """The summary helper test case.""" +class SummeryEditorTestCase(unittest.TestCase): + """The summary editor test case.""" def setUp(self) -> None: """Sets up the test. @@ -61,101 +61,101 @@ class SummeryHelperTestCase(unittest.TestCase): self.client, self.csrf_token = get_client(self.app, "editor") - def test_summary_helper(self) -> None: - """Test the summary helper. + def test_summary_editor(self) -> None: + """Test the summary editor. :return: None. """ - from accounting.transaction.summary_helper import SummaryHelper + from accounting.transaction.summary_editor import SummaryEditor for form in get_form_data(self.csrf_token): add_txn(self.client, form) with self.app.app_context(): - helper: SummaryHelper = SummaryHelper() + editor: SummaryEditor = SummaryEditor() # Debit-General - self.assertEqual(len(helper.debit.general.tags), 2) - self.assertEqual(helper.debit.general.tags[0].name, "Lunch") - self.assertEqual(len(helper.debit.general.tags[0].accounts), 2) - self.assertEqual(helper.debit.general.tags[0].accounts[0].code, + self.assertEqual(len(editor.debit.general.tags), 2) + self.assertEqual(editor.debit.general.tags[0].name, "Lunch") + self.assertEqual(len(editor.debit.general.tags[0].accounts), 2) + self.assertEqual(editor.debit.general.tags[0].accounts[0].code, Accounts.MEAL) - self.assertEqual(helper.debit.general.tags[0].accounts[1].code, + self.assertEqual(editor.debit.general.tags[0].accounts[1].code, Accounts.PAYABLE) - self.assertEqual(helper.debit.general.tags[1].name, "Dinner") - self.assertEqual(len(helper.debit.general.tags[1].accounts), 2) - self.assertEqual(helper.debit.general.tags[1].accounts[0].code, + self.assertEqual(editor.debit.general.tags[1].name, "Dinner") + self.assertEqual(len(editor.debit.general.tags[1].accounts), 2) + self.assertEqual(editor.debit.general.tags[1].accounts[0].code, Accounts.MEAL) - self.assertEqual(helper.debit.general.tags[1].accounts[1].code, + self.assertEqual(editor.debit.general.tags[1].accounts[1].code, Accounts.PAYABLE) # Debit-Travel - self.assertEqual(len(helper.debit.travel.tags), 3) - self.assertEqual(helper.debit.travel.tags[0].name, "Bike") - self.assertEqual(len(helper.debit.travel.tags[0].accounts), 1) - self.assertEqual(helper.debit.travel.tags[0].accounts[0].code, + self.assertEqual(len(editor.debit.travel.tags), 3) + self.assertEqual(editor.debit.travel.tags[0].name, "Bike") + self.assertEqual(len(editor.debit.travel.tags[0].accounts), 1) + self.assertEqual(editor.debit.travel.tags[0].accounts[0].code, Accounts.TRAVEL) - self.assertEqual(helper.debit.travel.tags[1].name, "Taxi") - self.assertEqual(len(helper.debit.travel.tags[1].accounts), 1) - self.assertEqual(helper.debit.travel.tags[1].accounts[0].code, + self.assertEqual(editor.debit.travel.tags[1].name, "Taxi") + self.assertEqual(len(editor.debit.travel.tags[1].accounts), 1) + self.assertEqual(editor.debit.travel.tags[1].accounts[0].code, Accounts.TRAVEL) - self.assertEqual(helper.debit.travel.tags[2].name, "Airplane") - self.assertEqual(len(helper.debit.travel.tags[2].accounts), 1) - self.assertEqual(helper.debit.travel.tags[2].accounts[0].code, + self.assertEqual(editor.debit.travel.tags[2].name, "Airplane") + self.assertEqual(len(editor.debit.travel.tags[2].accounts), 1) + self.assertEqual(editor.debit.travel.tags[2].accounts[0].code, Accounts.TRAVEL) # Debit-Bus - self.assertEqual(len(helper.debit.bus.tags), 2) - self.assertEqual(helper.debit.bus.tags[0].name, "Train") - self.assertEqual(len(helper.debit.bus.tags[0].accounts), 1) - self.assertEqual(helper.debit.bus.tags[0].accounts[0].code, + self.assertEqual(len(editor.debit.bus.tags), 2) + self.assertEqual(editor.debit.bus.tags[0].name, "Train") + self.assertEqual(len(editor.debit.bus.tags[0].accounts), 1) + self.assertEqual(editor.debit.bus.tags[0].accounts[0].code, Accounts.TRAVEL) - self.assertEqual(helper.debit.bus.tags[1].name, "Bus") - self.assertEqual(len(helper.debit.bus.tags[1].accounts), 1) - self.assertEqual(helper.debit.bus.tags[1].accounts[0].code, + self.assertEqual(editor.debit.bus.tags[1].name, "Bus") + self.assertEqual(len(editor.debit.bus.tags[1].accounts), 1) + self.assertEqual(editor.debit.bus.tags[1].accounts[0].code, Accounts.TRAVEL) # Credit-General - self.assertEqual(len(helper.credit.general.tags), 2) - self.assertEqual(helper.credit.general.tags[0].name, "Lunch") - self.assertEqual(len(helper.credit.general.tags[0].accounts), 3) - self.assertEqual(helper.credit.general.tags[0].accounts[0].code, + self.assertEqual(len(editor.credit.general.tags), 2) + self.assertEqual(editor.credit.general.tags[0].name, "Lunch") + self.assertEqual(len(editor.credit.general.tags[0].accounts), 3) + self.assertEqual(editor.credit.general.tags[0].accounts[0].code, Accounts.PAYABLE) - self.assertEqual(helper.credit.general.tags[0].accounts[1].code, + self.assertEqual(editor.credit.general.tags[0].accounts[1].code, Accounts.BANK) - self.assertEqual(helper.credit.general.tags[0].accounts[2].code, + self.assertEqual(editor.credit.general.tags[0].accounts[2].code, Accounts.CASH) - self.assertEqual(helper.credit.general.tags[1].name, "Dinner") - self.assertEqual(len(helper.credit.general.tags[1].accounts), 2) - self.assertEqual(helper.credit.general.tags[1].accounts[0].code, + self.assertEqual(editor.credit.general.tags[1].name, "Dinner") + self.assertEqual(len(editor.credit.general.tags[1].accounts), 2) + self.assertEqual(editor.credit.general.tags[1].accounts[0].code, Accounts.BANK) - self.assertEqual(helper.credit.general.tags[1].accounts[1].code, + self.assertEqual(editor.credit.general.tags[1].accounts[1].code, Accounts.PAYABLE) # Credit-Travel - self.assertEqual(len(helper.credit.travel.tags), 2) - self.assertEqual(helper.credit.travel.tags[0].name, "Bike") - self.assertEqual(len(helper.credit.travel.tags[0].accounts), 2) - self.assertEqual(helper.credit.travel.tags[0].accounts[0].code, + self.assertEqual(len(editor.credit.travel.tags), 2) + self.assertEqual(editor.credit.travel.tags[0].name, "Bike") + self.assertEqual(len(editor.credit.travel.tags[0].accounts), 2) + self.assertEqual(editor.credit.travel.tags[0].accounts[0].code, Accounts.PAYABLE) - self.assertEqual(helper.credit.travel.tags[0].accounts[1].code, + self.assertEqual(editor.credit.travel.tags[0].accounts[1].code, Accounts.PREPAID) - self.assertEqual(helper.credit.travel.tags[1].name, "Taxi") - self.assertEqual(len(helper.credit.travel.tags[1].accounts), 2) - self.assertEqual(helper.credit.travel.tags[1].accounts[0].code, + self.assertEqual(editor.credit.travel.tags[1].name, "Taxi") + self.assertEqual(len(editor.credit.travel.tags[1].accounts), 2) + self.assertEqual(editor.credit.travel.tags[1].accounts[0].code, Accounts.PAYABLE) - self.assertEqual(helper.credit.travel.tags[1].accounts[1].code, + self.assertEqual(editor.credit.travel.tags[1].accounts[1].code, Accounts.CASH) # Credit-Bus - self.assertEqual(len(helper.credit.bus.tags), 2) - self.assertEqual(helper.credit.bus.tags[0].name, "Train") - self.assertEqual(len(helper.credit.bus.tags[0].accounts), 2) - self.assertEqual(helper.credit.bus.tags[0].accounts[0].code, + self.assertEqual(len(editor.credit.bus.tags), 2) + self.assertEqual(editor.credit.bus.tags[0].name, "Train") + self.assertEqual(len(editor.credit.bus.tags[0].accounts), 2) + self.assertEqual(editor.credit.bus.tags[0].accounts[0].code, Accounts.PREPAID) - self.assertEqual(helper.credit.bus.tags[0].accounts[1].code, + self.assertEqual(editor.credit.bus.tags[0].accounts[1].code, Accounts.PAYABLE) - self.assertEqual(helper.credit.bus.tags[1].name, "Bus") - self.assertEqual(len(helper.credit.bus.tags[1].accounts), 1) - self.assertEqual(helper.credit.bus.tags[1].accounts[0].code, + self.assertEqual(editor.credit.bus.tags[1].name, "Bus") + self.assertEqual(len(editor.credit.bus.tags[1].accounts), 1) + self.assertEqual(editor.credit.bus.tags[1].accounts[0].code, Accounts.PREPAID)