show exchange rate in transaction edit page when the currencies of source account and destination account are different

This commit is contained in:
MaysWind
2024-03-04 00:08:53 +08:00
parent bed2aef7f8
commit deb465377e
3 changed files with 68 additions and 2 deletions
@@ -73,7 +73,7 @@
:disabled="loading || submitting"
:persistent-placeholder="true"
:hide="transaction.hideAmount"
:label="$t('Transfer In Amount')"
:label="transferInAmountTitle"
:placeholder="$t('Transfer In Amount')"
v-model="transaction.destinationAmount"/>
</v-col>
@@ -325,6 +325,9 @@ import {
getTimezoneOffsetMinutes,
getCurrentUnixTime
} from '@/lib/datetime.js';
import {
getAdaptiveDisplayAmountRate
} from '@/lib/currency.js';
import {
getFirstAvailableCategoryId
} from '@/lib/category.js';
@@ -417,6 +420,24 @@ export default {
return 'Account';
}
},
transferInAmountTitle() {
const sourceAccount = this.allAccountsMap[this.transaction.sourceAccountId];
const destinationAccount = this.allAccountsMap[this.transaction.destinationAccountId];
if (!sourceAccount || !destinationAccount || sourceAccount.currency === destinationAccount.currency) {
return this.$t('Transfer In Amount');
}
const fromExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[sourceAccount.currency];
const toExchangeRate = this.exchangeRatesStore.latestExchangeRateMap[destinationAccount.currency];
const amountRate = getAdaptiveDisplayAmountRate(this.transaction.sourceAmount, this.transaction.destinationAmount, fromExchangeRate, toExchangeRate, this.settingsStore.appSettings.thousandsSeparator);
if (!amountRate) {
return this.$t('Transfer In Amount');
}
return this.$t('Transfer In Amount') + ` (${amountRate})`;
},
defaultCurrency() {
return this.userStore.currentUserDefaultCurrency;
},