diff --git a/src/stores/account.ts b/src/stores/account.ts index f2e68ef2..7af9fc47 100644 --- a/src/stores/account.ts +++ b/src/stores/account.ts @@ -16,7 +16,6 @@ import { } from '@/models/account.ts'; import { isNumber, isEquals } from '@/lib/common.ts'; -import { getCurrentUnixTime } from '@/lib/datetime.ts'; import { getCategorizedAccountsMap, getAllFilteredAccountsBalance } from '@/lib/account.ts'; import services from '@/lib/services.ts'; import logger from '@/lib/logger.ts'; @@ -268,14 +267,6 @@ export const useAccountsStore = defineStore('accounts', () => { return shownAccountCount; }); - function generateNewAccountModel(): Account { - return Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()); - } - - function generateNewSubAccountModel(parentAccount: Account): Account { - return parentAccount.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()); - } - function updateAccountListInvalidState(invalidState: boolean): void { accountListStateInvalid.value = invalidState; } @@ -990,8 +981,6 @@ export const useAccountsStore = defineStore('accounts', () => { allAvailableAccountsCount, allVisibleAccountsCount, // functions - generateNewAccountModel, - generateNewSubAccountModel, updateAccountListInvalidState, resetAccounts, getFirstShowingIds, diff --git a/src/views/base/accounts/AccountEditPageBase.ts b/src/views/base/accounts/AccountEditPageBase.ts index 9ea3a8c3..ea11f62b 100644 --- a/src/views/base/accounts/AccountEditPageBase.ts +++ b/src/views/base/accounts/AccountEditPageBase.ts @@ -2,14 +2,15 @@ import { ref, computed, watch } from 'vue'; import { useI18n } from '@/locales/helpers.ts'; -import { useAccountsStore } from '@/stores/account.ts'; +import { useUserStore } from '@/stores/user.ts'; import type { TypeAndDisplayName } from '@/core/base.ts'; import { AccountCategory, AccountType } from '@/core/account.ts'; import type { LocalizedCurrencyInfo } from '@/core/currency.ts'; import type { LocalizedAccountCategory } from '@/core/account.ts'; -import type { Account } from '@/models/account.ts'; +import { Account } from '@/models/account.ts'; +import { getCurrentUnixTime } from '@/lib/datetime.ts'; import { setAccountSuitableIcon } from '@/lib/account.ts'; export interface DayAndDisplayName { @@ -19,13 +20,14 @@ export interface DayAndDisplayName { export function useAccountEditPageBaseBase() { const { tt, getAllCurrencies, getAllAccountCategories, getAllAccountTypes, getMonthdayShortName } = useI18n(); - const accountsStore = useAccountsStore(); + + const userStore = useUserStore(); const editAccountId = ref(null); const clientSessionId = ref(''); const loading = ref(false); const submitting = ref(false); - const account = ref(accountsStore.generateNewAccountModel()); + const account = ref(Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime())); const subAccounts = ref([]); const title = computed(() => { @@ -133,7 +135,7 @@ export function useAccountEditPageBaseBase() { return false; } - const subAccount = accountsStore.generateNewSubAccountModel(account.value); + const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()); subAccounts.value.push(subAccount); return true; } @@ -144,7 +146,7 @@ export function useAccountEditPageBaseBase() { if (newAccount.childrenAccounts && newAccount.childrenAccounts.length > 0) { for (let i = 0; i < newAccount.childrenAccounts.length; i++) { - const subAccount = accountsStore.generateNewSubAccountModel(account.value); + const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()); subAccount.from(newAccount.childrenAccounts[i]); subAccounts.value.push(subAccount); diff --git a/src/views/desktop/accounts/list/dialogs/EditDialog.vue b/src/views/desktop/accounts/list/dialogs/EditDialog.vue index 6600f2f1..3cf6dda3 100644 --- a/src/views/desktop/accounts/list/dialogs/EditDialog.vue +++ b/src/views/desktop/accounts/list/dialogs/EditDialog.vue @@ -204,14 +204,16 @@ import { ref, computed, useTemplateRef, watch } from 'vue'; import { useI18n } from '@/locales/helpers.ts'; import { useAccountEditPageBaseBase } from '@/views/base/accounts/AccountEditPageBase.ts'; +import { useUserStore } from '@/stores/user.ts'; import { useAccountsStore } from '@/stores/account.ts'; import { AccountType } from '@/core/account.ts'; import { ALL_ACCOUNT_ICONS } from '@/consts/icon.ts'; import { ALL_ACCOUNT_COLORS } from '@/consts/color.ts'; -import type { Account } from '@/models/account.ts'; +import { Account } from '@/models/account.ts'; import { isNumber } from '@/lib/common.ts'; +import { getCurrentUnixTime } from '@/lib/datetime.ts'; import { generateRandomUUID } from '@/lib/misc.ts'; import { setAccountSuitableIcon } from '@/lib/account.ts'; @@ -254,6 +256,7 @@ const { setAccount } = useAccountEditPageBaseBase(); +const userStore = useUserStore(); const accountsStore = useAccountsStore(); const icons = { @@ -285,7 +288,7 @@ function open(options?: { id?: string, currentAccount?: Account, category?: numb loading.value = true; submitting.value = false; - const newAccount = accountsStore.generateNewAccountModel(); + const newAccount = Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()); account.value.from(newAccount); subAccounts.value = []; currentAccountIndex.value = -1;