From b6ae946f323960f6a9f24633e3795ac63e93c635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Tue, 18 Apr 2023 07:55:00 +0800 Subject: [PATCH] Removed the account code from the journal entry form for mobile screens. --- .../journal_entry/forms/line_item.py | 13 ++++++++ .../journal_entry/utils/account_option.py | 2 ++ .../journal_entry/utils/description_editor.py | 8 +++++ .../static/js/description-editor.js | 9 ++--- .../js/journal-entry-account-selector.js | 7 ++++ .../static/js/journal-entry-form.js | 33 ++++++++++++++----- .../js/journal-entry-line-item-editor.js | 2 +- .../static/js/original-line-item-selector.js | 2 +- .../include/account-selector-modal.html | 2 +- .../include/description-editor-modal.html | 2 +- .../journal-entry/include/form-line-item.html | 7 ++-- .../original-line-item-selector-modal.html | 2 +- 12 files changed, 70 insertions(+), 19 deletions(-) diff --git a/src/accounting/journal_entry/forms/line_item.py b/src/accounting/journal_entry/forms/line_item.py index 0512b6b..f0ef8f2 100644 --- a/src/accounting/journal_entry/forms/line_item.py +++ b/src/accounting/journal_entry/forms/line_item.py @@ -267,6 +267,19 @@ class LineItemForm(FlaskForm): self.journal_entry_form: JournalEntryForm | None = None """The source journal entry form.""" + @property + def account_title(self) -> str: + """Returns the title of the account. + + :return: The title of the account. + """ + if self.account_code.data is None: + return "" + account: Account | None = Account.find_by_code(self.account_code.data) + if account is None: + return "" + return account.title + @property def account_text(self) -> str: """Returns the text representation of the account. diff --git a/src/accounting/journal_entry/utils/account_option.py b/src/accounting/journal_entry/utils/account_option.py index 6c35442..2d7e718 100644 --- a/src/accounting/journal_entry/utils/account_option.py +++ b/src/accounting/journal_entry/utils/account_option.py @@ -32,6 +32,8 @@ class AccountOption: """The account ID.""" self.code: str = account.code """The account code.""" + self.title: str = account.title + """The account title.""" self.query_values: list[str] = account.query_values """The values to be queried.""" self.__str: str = str(account) diff --git a/src/accounting/journal_entry/utils/description_editor.py b/src/accounting/journal_entry/utils/description_editor.py index fb6869c..193bfaf 100644 --- a/src/accounting/journal_entry/utils/description_editor.py +++ b/src/accounting/journal_entry/utils/description_editor.py @@ -54,6 +54,14 @@ class DescriptionAccount: """ return str(self.__account) + @property + def title(self) -> str: + """Returns the account title. + + :return: The account title. + """ + return self.__account.title + def add_freq(self, freq: int) -> None: """Adds the frequency of an account. diff --git a/src/accounting/static/js/description-editor.js b/src/accounting/static/js/description-editor.js index 18adc2f..dde5d5d 100644 --- a/src/accounting/static/js/description-editor.js +++ b/src/accounting/static/js/description-editor.js @@ -364,12 +364,13 @@ class DescriptionEditorAccount extends JournalEntryAccount { * * @param editor {DescriptionEditor} the description editor * @param code {string} the account code + * @param title {string} the account title * @param text {string} the account text * @param isNeedOffset {boolean} true if the line items in the account needs offset, or false otherwise * @param button {HTMLButtonElement} the account button */ - constructor(editor, code, text, isNeedOffset, button) { - super(code, text, isNeedOffset); + constructor(editor, code, title, text, isNeedOffset, button) { + super(code, title, text, isNeedOffset); this.#element = button; this.#element.onclick = () => editor.selectAccount(this); } @@ -424,7 +425,7 @@ class DescriptionEditorSuggestedAccount extends DescriptionEditorAccount { * @param button {HTMLButtonElement} the account button */ constructor(editor, button) { - super(editor, button.dataset.code, button.dataset.text, button.classList.contains("accounting-account-is-need-offset"), button); + super(editor, button.dataset.code, button.dataset.title, button.dataset.text, button.classList.contains("accounting-account-is-need-offset"), button); } } @@ -441,7 +442,7 @@ class DescriptionEditorConfirmedAccount extends DescriptionEditorAccount { * @param button {HTMLButtonElement} the account button */ constructor(editor, button) { - super(editor, "", "", false, button); + super(editor, "", "", "", false, button); this.isConfirmedAccount = true; } diff --git a/src/accounting/static/js/journal-entry-account-selector.js b/src/accounting/static/js/journal-entry-account-selector.js index e3ba184..39e0b95 100644 --- a/src/accounting/static/js/journal-entry-account-selector.js +++ b/src/accounting/static/js/journal-entry-account-selector.js @@ -202,6 +202,12 @@ class JournalEntryAccountOption { */ code; + /** + * The account title + * @type {string} + */ + title; + /** * The account text * @type {string} @@ -235,6 +241,7 @@ class JournalEntryAccountOption { constructor(selector, element) { this.#element = element; this.code = element.dataset.code; + this.title = element.dataset.title; this.text = element.dataset.text; this.#isInUse = element.classList.contains("accounting-account-is-in-use"); this.isNeedOffset = element.classList.contains("accounting-account-is-need-offset"); diff --git a/src/accounting/static/js/journal-entry-form.js b/src/accounting/static/js/journal-entry-form.js index e49df09..592f710 100644 --- a/src/accounting/static/js/journal-entry-form.js +++ b/src/accounting/static/js/journal-entry-form.js @@ -791,6 +791,12 @@ class JournalEntryAccount { */ code; + /** + * The account title + * @type {string} + */ + title; + /** * The account text * @type {string} @@ -807,11 +813,13 @@ class JournalEntryAccount { * Constructs a journal entry account. * * @param code {string} the account code + * @param title {string} the account title * @param text {string} the account text * @param isNeedOffset {boolean} true if the line items in the account needs offset, or false otherwise */ - constructor(code, text, isNeedOffset) { + constructor(code, title, text, isNeedOffset) { this.code = code; + this.title = title; this.text = text; this.isNeedOffset = isNeedOffset; } @@ -822,7 +830,7 @@ class JournalEntryAccount { * @return {JournalEntryAccount} the copy of the account */ copy() { - return new JournalEntryAccount(this.code, this.text, this.isNeedOffset); + return new JournalEntryAccount(this.code, this.title, this.text, this.isNeedOffset); } } @@ -887,10 +895,16 @@ class LineItemSubForm { #accountCode; /** - * The text display of the account - * @type {HTMLDivElement} + * The code part of the text display of the account + * @type {HTMLSpanElement} */ - #accountText; + #accountTextCode; + + /** + * The title part of the text display of the account + * @type {HTMLSpanElement} + */ + #accountTextTitle; /** * The description @@ -957,7 +971,8 @@ class LineItemSubForm { this.#error = document.getElementById(`${prefix}-error`); this.#no = document.getElementById(`${prefix}-no`); this.#accountCode = document.getElementById(`${prefix}-account-code`); - this.#accountText = document.getElementById(`${prefix}-account-text`); + this.#accountTextCode = document.getElementById(`${prefix}-account-text-code`); + this.#accountTextTitle = document.getElementById(`${prefix}-account-text-title`); this.#description = document.getElementById(`${prefix}-description`); this.#descriptionText = document.getElementById(`${prefix}-description-text`); this.#originalLineItemId = document.getElementById(`${prefix}-original-line-item-id`); @@ -1024,7 +1039,7 @@ class LineItemSubForm { * @return {JournalEntryAccount|null} the account */ get account() { - return this.#accountCode.value === null? null: new JournalEntryAccount(this.#accountCode.value, this.#accountCode.dataset.text, this.#accountCode.classList.contains("accounting-account-is-need-offset")); + return this.#accountCode.value === null? null: new JournalEntryAccount(this.#accountCode.value, this.#accountCode.dataset.title, this.#accountCode.dataset.text, this.#accountCode.classList.contains("accounting-account-is-need-offset")); } /** @@ -1092,13 +1107,15 @@ class LineItemSubForm { this.#originalLineItemText.innerText = A_("Offset %(item)s", {item: editor.originalLineItemText}); } this.#accountCode.value = editor.account.code; + this.#accountCode.dataset.title = editor.account.title; this.#accountCode.dataset.text = editor.account.text; if (editor.account.isNeedOffset) { this.#accountCode.classList.add("accounting-account-is-need-offset"); } else { this.#accountCode.classList.remove("accounting-account-is-need-offset"); } - this.#accountText.innerText = editor.account.text; + this.#accountTextCode.innerText = editor.account.code + this.#accountTextTitle.innerText = editor.account.title this.#description.value = editor.description === null? "": editor.description; this.#descriptionText.innerText = editor.description === null? "": editor.description; this.#amount.value = editor.amount; diff --git a/src/accounting/static/js/journal-entry-line-item-editor.js b/src/accounting/static/js/journal-entry-line-item-editor.js index 6fffe09..d4d9b14 100644 --- a/src/accounting/static/js/journal-entry-line-item-editor.js +++ b/src/accounting/static/js/journal-entry-line-item-editor.js @@ -356,7 +356,7 @@ class JournalEntryLineItemEditor { */ saveAccount(account) { this.#accountControl.classList.add("accounting-not-empty"); - this.account = new JournalEntryAccount(account.code, account.text, account.isNeedOffset); + this.account = new JournalEntryAccount(account.code, account.title, account.text, account.isNeedOffset); this.isAccountConfirmed = true; this.#accountText.innerText = account.text; this.#validateAccount(); diff --git a/src/accounting/static/js/original-line-item-selector.js b/src/accounting/static/js/original-line-item-selector.js index 3f085bf..c5fcf78 100644 --- a/src/accounting/static/js/original-line-item-selector.js +++ b/src/accounting/static/js/original-line-item-selector.js @@ -284,7 +284,7 @@ class OriginalLineItem { this.date = element.dataset.date; this.#debitCredit = element.dataset.debitCredit; this.#currencyCode = element.dataset.currencyCode; - this.account = new JournalEntryAccount(element.dataset.accountCode, element.dataset.accountText, false); + this.account = new JournalEntryAccount(element.dataset.accountCode, element.dataset.accountTitle, element.dataset.accountText, false); this.description = element.dataset.description; this.bareNetBalance = new Decimal(element.dataset.netBalance); this.netBalance = this.bareNetBalance; diff --git a/src/accounting/templates/accounting/journal-entry/include/account-selector-modal.html b/src/accounting/templates/accounting/journal-entry/include/account-selector-modal.html index 559cca7..917ea3c 100644 --- a/src/accounting/templates/accounting/journal-entry/include/account-selector-modal.html +++ b/src/accounting/templates/accounting/journal-entry/include/account-selector-modal.html @@ -37,7 +37,7 @@ First written: 2023/2/25