From 94391b02a68e33c81ac69af158ad13fec23b45d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 31 Mar 2023 23:54:56 +0800 Subject: [PATCH] Added the copy() method to the JavaScript JournalEntryAccount class, and replaced the accountCode and accountText fields with the account field in the OriginalLineItem class. --- .../static/js/journal-entry-line-item-editor.js | 11 ++++++++++- .../static/js/original-line-item-selector.js | 15 ++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) 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 441443f..fdaf5f9 100644 --- a/src/accounting/static/js/journal-entry-line-item-editor.js +++ b/src/accounting/static/js/journal-entry-line-item-editor.js @@ -279,7 +279,7 @@ class JournalEntryLineItemEditor { this.description = originalLineItem.description === ""? null: originalLineItem.description; this.#descriptionText.innerText = originalLineItem.description; this.#accountControl.classList.add("accounting-not-empty"); - this.account = new JournalEntryAccount(originalLineItem.accountCode, originalLineItem.accountText, false); + this.account = originalLineItem.account.copy(); this.#accountText.innerText = this.account.text; this.#amountInput.value = String(originalLineItem.netBalance); this.#amountInput.max = String(originalLineItem.netBalance); @@ -607,4 +607,13 @@ class JournalEntryAccount { this.text = text; this.isNeedOffset = isNeedOffset; } + + /** + * Returns a copy of the account. + * + * @return {JournalEntryAccount} the copy of the account + */ + copy() { + return new JournalEntryAccount(this.code, this.text, this.isNeedOffset); + } } diff --git a/src/accounting/static/js/original-line-item-selector.js b/src/accounting/static/js/original-line-item-selector.js index eb4bbf6..117e7c5 100644 --- a/src/accounting/static/js/original-line-item-selector.js +++ b/src/accounting/static/js/original-line-item-selector.js @@ -230,16 +230,10 @@ class OriginalLineItem { #currencyCode; /** - * The account code - * @type {string} + * The account + * @type {JournalEntryAccount} */ - accountCode; - - /** - * The account text - * @type {string} - */ - accountText; + account; /** * The description @@ -290,8 +284,7 @@ class OriginalLineItem { this.date = element.dataset.date; this.#debitCredit = element.dataset.debitCredit; this.#currencyCode = element.dataset.currencyCode; - this.accountCode = element.dataset.accountCode; - this.accountText = element.dataset.accountText; + this.account = new JournalEntryAccount(element.dataset.accountCode, element.dataset.accountText, false); this.description = element.dataset.description; this.bareNetBalance = new Decimal(element.dataset.netBalance); this.netBalance = this.bareNetBalance;