Add exchange rate feature with multi-currency transactions and transfers support (#1099)

Co-authored-by: Pedro J. Aramburu <pedro@joakin.dev>
This commit is contained in:
Pedro J. Aramburu
2026-04-08 16:05:58 -03:00
committed by GitHub
parent 8e81e967fc
commit f699660479
48 changed files with 1886 additions and 73 deletions

View File

@@ -0,0 +1,59 @@
import ExchangeRateFormController from "controllers/exchange_rate_form_controller";
// Connects to data-controller="transfer-form"
export default class extends ExchangeRateFormController {
static targets = [
...ExchangeRateFormController.targets,
"fromAccount",
"toAccount"
];
hasRequiredExchangeRateTargets() {
if (!this.hasFromAccountTarget || !this.hasToAccountTarget || !this.hasDateTarget) {
return false;
}
return true;
}
getExchangeRateContext() {
if (!this.hasRequiredExchangeRateTargets()) {
return null;
}
const fromAccountId = this.fromAccountTarget.value;
const toAccountId = this.toAccountTarget.value;
const date = this.dateTarget.value;
if (!fromAccountId || !toAccountId) {
return null;
}
const fromCurrency = this.accountCurrenciesValue[fromAccountId];
const toCurrency = this.accountCurrenciesValue[toAccountId];
if (!fromCurrency || !toCurrency) {
return null;
}
return {
fromCurrency,
toCurrency,
date
};
}
isCurrentExchangeRateState(fromCurrency, toCurrency, date) {
if (!this.hasRequiredExchangeRateTargets()) {
return false;
}
const currentFromAccountId = this.fromAccountTarget.value;
const currentToAccountId = this.toAccountTarget.value;
const currentFromCurrency = this.accountCurrenciesValue[currentFromAccountId];
const currentToCurrency = this.accountCurrenciesValue[currentToAccountId];
const currentDate = this.dateTarget.value;
return fromCurrency === currentFromCurrency && toCurrency === currentToCurrency && date === currentDate;
}
}