Skip to content

Commit

Permalink
fix the wrong account balance in transaction edit page due to #a0e3a2…
Browse files Browse the repository at this point in the history
…69a0098d05fa1a17eee4cce393869fc5cc
  • Loading branch information
mayswind committed Feb 11, 2025
1 parent 2e01e55 commit 0ca2f8b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/locales/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ import {
isString,
isNumber,
isBoolean,
copyObjectTo,
copyArrayTo
} from '@/lib/common.ts';

Expand Down Expand Up @@ -1471,7 +1470,7 @@ export function useI18n() {
const ret: CategorizedAccountWithDisplayBalance[] = [];
const defaultCurrency = userStore.currentUserDefaultCurrency;
const allCategories = AccountCategory.values();
const categorizedAccounts: Record<number, CategorizedAccount> = copyObjectTo(getCategorizedAccountsMap(allVisibleAccounts), {}) as Record<number, CategorizedAccount>;
const categorizedAccounts: Record<number, CategorizedAccount> = getCategorizedAccountsMap(Account.cloneAccounts(allVisibleAccounts));

for (let i = 0; i < allCategories.length; i++) {
const category = allCategories[i];
Expand Down
31 changes: 31 additions & 0 deletions src/models/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0ca2f8b

Please sign in to comment.