From 0ca2f8b4a7f07f27a96f8018ffb2d118911ab3b8 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 12 Feb 2025 01:25:46 +0800 Subject: [PATCH] fix the wrong account balance in transaction edit page due to #a0e3a269a0098d05fa1a17eee4cce393869fc5cc --- src/locales/helpers.ts | 3 +-- src/models/account.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/locales/helpers.ts b/src/locales/helpers.ts index e561715b..29fe8b0a 100644 --- a/src/locales/helpers.ts +++ b/src/locales/helpers.ts @@ -111,7 +111,6 @@ import { isString, isNumber, isBoolean, - copyObjectTo, copyArrayTo } from '@/lib/common.ts'; @@ -1471,7 +1470,7 @@ export function useI18n() { const ret: CategorizedAccountWithDisplayBalance[] = []; const defaultCurrency = userStore.currentUserDefaultCurrency; const allCategories = AccountCategory.values(); - const categorizedAccounts: Record = copyObjectTo(getCategorizedAccountsMap(allVisibleAccounts), {}) as Record; + const categorizedAccounts: Record = getCategorizedAccountsMap(Account.cloneAccounts(allVisibleAccounts)); for (let i = 0; i < allCategories.length; i++) { const category = allCategories[i]; diff --git a/src/models/account.ts b/src/models/account.ts index 50e72092..515e9a69 100644 --- a/src/models/account.ts +++ b/src/models/account.ts @@ -235,6 +235,27 @@ export class Account implements AccountInfoResponse { return subAccountCurrencies; } + public clone(): Account { + return new Account( + this.id, + this.name, + this.parentId, + this.category, + this.type, + this.icon, + this.color, + this.currency, + this.balance, + this.comment, + this.displayOrder, + this.visible, + this.balanceTime, + this.creditCardStatementDate, + this.isAsset, + this.isLiability, + typeof(this.subAccounts) !== 'undefined' ? Account.cloneAccounts(this.subAccounts) : undefined); + } + public createNewSubAccount(currency: string, balanceTime: number): Account { return new Account( '', // id @@ -315,6 +336,16 @@ export class Account implements AccountInfoResponse { return defaultName; } + public static cloneAccounts(accounts: Account[]): Account[] { + const clonedAccounts: Account[] = []; + + for (const account of accounts) { + clonedAccounts.push(account.clone()); + } + + return clonedAccounts; + } + public static sortAccounts(accounts: Account[]): Account[] { if (!accounts || !accounts.length) { return accounts;