diff --git a/src/accounting/account/commands.py b/src/accounting/account/commands.py index cc9d370..c8c3352 100644 --- a/src/accounting/account/commands.py +++ b/src/accounting/account/commands.py @@ -29,7 +29,7 @@ from accounting.utils.user import has_user, get_user_pk AccountData = tuple[int, str, int, str, str, str, bool] """The format of the account data, as a list of (ID, base account code, number, -English, Traditional Chinese, Simplified Chinese, is-offset-needed) tuples.""" +English, Traditional Chinese, Simplified Chinese, is-need-offset) tuples.""" def __validate_username(ctx: click.core.Context, param: click.core.Option, @@ -92,14 +92,14 @@ def init_accounts_command(username: str) -> None: data: list[AccountData] = [] for base in bases_to_add: l10n: dict[str, str] = {x.locale: x.title for x in base.l10n} - is_offset_needed: bool = __is_offset_needed(base.code) + is_need_offset: bool = __is_need_offset(base.code) data.append((get_new_id(), base.code, 1, base.title_l10n, - l10n["zh_Hant"], l10n["zh_Hans"], is_offset_needed)) + l10n["zh_Hant"], l10n["zh_Hans"], is_need_offset)) __add_accounting_accounts(data, creator_pk) click.echo(F"{len(data)} added. Accounting accounts initialized.") -def __is_offset_needed(base_code: str) -> bool: +def __is_need_offset(base_code: str) -> bool: """Checks that whether entries in the account need offset. :param base_code: The code of the base account. @@ -134,7 +134,7 @@ def __add_accounting_accounts(data: list[AccountData], creator_pk: int)\ base_code=x[1], no=x[2], title_l10n=x[3], - is_offset_needed=x[6], + is_need_offset=x[6], created_by_id=creator_pk, updated_by_id=creator_pk) for x in data] diff --git a/src/accounting/account/forms.py b/src/accounting/account/forms.py index 7bd30a0..20ee455 100644 --- a/src/accounting/account/forms.py +++ b/src/accounting/account/forms.py @@ -80,7 +80,7 @@ class AccountForm(FlaskForm): filters=[strip_text], validators=[DataRequired(lazy_gettext("Please fill in the title"))]) """The title.""" - is_offset_needed = BooleanField( + is_need_offset = BooleanField( validators=[NoOffsetNominalAccount()]) """Whether the the entries of this account need offset.""" @@ -103,9 +103,9 @@ class AccountForm(FlaskForm): obj.no = count + 1 obj.title = self.title.data if self.base_code.data[0] in {"1", "2", "3"}: - obj.is_offset_needed = self.is_offset_needed.data + obj.is_need_offset = self.is_need_offset.data else: - obj.is_offset_needed = False + obj.is_need_offset = False if is_new: current_user_pk: int = get_current_user_pk() obj.created_by_id = current_user_pk diff --git a/src/accounting/account/queries.py b/src/accounting/account/queries.py index 9e6d9af..6c7683b 100644 --- a/src/accounting/account/queries.py +++ b/src/accounting/account/queries.py @@ -48,7 +48,7 @@ def get_account_query() -> list[Account]: code.contains(k), Account.id.in_(l10n_matches)] if k in gettext("Need offset"): - sub_conditions.append(Account.is_offset_needed) + sub_conditions.append(Account.is_need_offset) conditions.append(sa.or_(*sub_conditions)) return Account.query.filter(*conditions)\ diff --git a/src/accounting/models.py b/src/accounting/models.py index f9f6615..e37604b 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -114,7 +114,7 @@ class Account(db.Model): """The account number under the base account.""" title_l10n = db.Column("title", db.String, nullable=False) """The title.""" - is_offset_needed = db.Column(db.Boolean, nullable=False, default=False) + is_need_offset = db.Column(db.Boolean, nullable=False, default=False) """Whether the entries of this account need offset.""" created_at = db.Column(db.DateTime(timezone=True), nullable=False, server_default=db.func.now()) @@ -702,7 +702,7 @@ class JournalEntry(db.Model): :return: True if the entry needs offset, or False otherwise. """ - if not self.account.is_offset_needed: + if not self.account.is_need_offset: return False if self.account.base_code[0] == "1" and not self.is_debit: return False diff --git a/src/accounting/report/reports/search.py b/src/accounting/report/reports/search.py index 3f2f790..b2d14e3 100644 --- a/src/accounting/report/reports/search.py +++ b/src/accounting/report/reports/search.py @@ -97,7 +97,7 @@ class EntryCollector: code.contains(k), Account.id.in_(select_l10n)] if k in gettext("Need offset"): - conditions.append(Account.is_offset_needed) + conditions.append(Account.is_need_offset) return sa.select(Account.id).filter(sa.or_(*conditions)) @staticmethod diff --git a/src/accounting/static/js/account-form.js b/src/accounting/static/js/account-form.js index 1ea9919..03482c2 100644 --- a/src/accounting/static/js/account-form.js +++ b/src/accounting/static/js/account-form.js @@ -83,16 +83,16 @@ class AccountForm { #titleError; /** - * The control of the is-offset-needed option + * The control of the is-need-offset option * @type {HTMLDivElement} */ - #isOffsetNeededControl; + #isNeedOffsetControl; /** - * The is-offset-needed option + * The is-need-offset option * @type {HTMLInputElement} */ - #isOffsetNeeded; + #isNeedOffset; /** * Constructs the account form. @@ -107,8 +107,8 @@ class AccountForm { this.#baseError = document.getElementById("accounting-base-error"); this.#title = document.getElementById("accounting-title"); this.#titleError = document.getElementById("accounting-title-error"); - this.#isOffsetNeededControl = document.getElementById("accounting-is-offset-needed-control"); - this.#isOffsetNeeded = document.getElementById("accounting-is-offset-needed"); + this.#isNeedOffsetControl = document.getElementById("accounting-is-need-offset-control"); + this.#isNeedOffset = document.getElementById("accounting-is-need-offset"); this.#formElement.onsubmit = () => { return this.#validateForm(); }; @@ -138,12 +138,12 @@ class AccountForm { this.#baseCode.value = code; this.#base.innerText = text; if (["1", "2", "3"].includes(code.substring(0, 1))) { - this.#isOffsetNeededControl.classList.remove("d-none"); - this.#isOffsetNeeded.disabled = false; + this.#isNeedOffsetControl.classList.remove("d-none"); + this.#isNeedOffset.disabled = false; } else { - this.#isOffsetNeededControl.classList.add("d-none"); - this.#isOffsetNeeded.disabled = true; - this.#isOffsetNeeded.checked = false; + this.#isNeedOffsetControl.classList.add("d-none"); + this.#isNeedOffset.disabled = true; + this.#isNeedOffset.checked = false; } this.#validateBase(); } diff --git a/src/accounting/static/js/account-selector.js b/src/accounting/static/js/account-selector.js index 6b20c83..9d05c08 100644 --- a/src/accounting/static/js/account-selector.js +++ b/src/accounting/static/js/account-selector.js @@ -105,7 +105,7 @@ class AccountSelector { }; this.#clearButton.onclick = () => this.#entryEditor.clearAccount(); for (const option of this.#options) { - option.onclick = () => this.#entryEditor.saveAccount(option.dataset.code, option.dataset.content, option.classList.contains("accounting-account-is-offset-needed")); + option.onclick = () => this.#entryEditor.saveAccount(option.dataset.code, option.dataset.content, option.classList.contains("accounting-account-is-need-offset")); } this.#query.addEventListener("input", () => { this.#filterOptions(); diff --git a/src/accounting/static/js/journal-entry-editor.js b/src/accounting/static/js/journal-entry-editor.js index 7c091db..345cfbc 100644 --- a/src/accounting/static/js/journal-entry-editor.js +++ b/src/accounting/static/js/journal-entry-editor.js @@ -374,10 +374,10 @@ class JournalEntryEditor { * * @param code {string} the account code * @param text {string} the account text - * @param isOffsetNeeded {boolean} true if the journal entries in the account need offset or false otherwise + * @param isNeedOffset {boolean} true if the journal entries in the account need offset or false otherwise */ - saveAccount(code, text, isOffsetNeeded) { - this.isNeedOffset = isOffsetNeeded; + saveAccount(code, text, isNeedOffset) { + this.isNeedOffset = isNeedOffset; this.#accountControl.classList.add("accounting-not-empty"); this.accountCode = code; this.accountText = text; diff --git a/src/accounting/static/js/summary-editor.js b/src/accounting/static/js/summary-editor.js index 8f336e0..147eb93 100644 --- a/src/accounting/static/js/summary-editor.js +++ b/src/accounting/static/js/summary-editor.js @@ -215,7 +215,7 @@ class SummaryEditor { #submit() { bootstrap.Modal.getOrCreateInstance(this.#modal).hide(); if (this.#selectedAccount !== null) { - this.#entryEditor.saveSummaryWithAccount(this.summary.value, this.#selectedAccount.dataset.code, this.#selectedAccount.dataset.text, this.#selectedAccount.classList.contains("accounting-account-is-offset-needed")); + this.#entryEditor.saveSummaryWithAccount(this.summary.value, this.#selectedAccount.dataset.code, this.#selectedAccount.dataset.text, this.#selectedAccount.classList.contains("accounting-account-is-need-offset")); } else { this.#entryEditor.saveSummary(this.summary.value); } diff --git a/src/accounting/templates/accounting/account/detail.html b/src/accounting/templates/accounting/account/detail.html index f23ce5f..13c16f9 100644 --- a/src/accounting/templates/accounting/account/detail.html +++ b/src/accounting/templates/accounting/account/detail.html @@ -85,7 +85,7 @@ First written: 2023/1/31