Fix exchange rate parity across all document types

- Fix exchange-rate service types to match actual backend response shapes
  (exchangeRate array, activeProvider success/error, used currencies as strings)
- Add ExchangeRateConverter to payments, expenses, and recurring invoices
- Set currency_id from customer currency in invoice/estimate selectCustomer()
- Load globalStore.currencies in ExchangeRateConverter on mount
- Pass driver/key/driver_config params to getSupportedCurrencies in provider modal
- Fix OpenExchangeRateDriver validateConnection to use base=USD (free plan compat)
- Fix checkActiveCurrencies SQLite whereJsonContains with array values
- Remove broken currency/companyCurrency props from ExpenseCreateView, use stores
- Show base currency equivalent in document line items and totals when exchange
  rate is active
This commit is contained in:
Darko Gjorgjijoski
2026-04-06 21:07:50 +02:00
parent e64529468c
commit b0b7d40c73
12 changed files with 213 additions and 54 deletions

View File

@@ -128,6 +128,15 @@
:amount="total"
:currency="selectedCurrency"
/>
<span
v-if="showBaseCurrencyEquivalent"
class="block text-xs text-muted mt-1"
>
<BaseFormatMoney
:amount="baseCurrencyTotal"
:currency="companyCurrency"
/>
</span>
</span>
<div class="flex items-center justify-center w-6 h-10 mx-2">
<BaseIcon
@@ -184,6 +193,7 @@ import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { required, between, maxLength, helpers, minValue } from '@vuelidate/validators'
import useVuelidate from '@vuelidate/core'
import { useCompanyStore } from '../../../stores/company.store'
import DocumentItemRowTax from './DocumentItemRowTax.vue'
import DragIcon from '@v2/components/icons/DragIcon.vue'
import { generateClientId } from '../../../utils'
@@ -221,6 +231,7 @@ const props = withDefaults(defineProps<Props>(), {
const emit = defineEmits<Emits>()
const { t } = useI18n()
const companyStore = useCompanyStore()
const formData = computed<DocumentFormData>(() => {
return props.store[props.storeProp] as DocumentFormData
@@ -285,6 +296,17 @@ const totalSimpleTax = computed<number>(() => {
const totalTax = computed<number>(() => totalSimpleTax.value)
const companyCurrency = computed(() => companyStore.selectedCompanyCurrency)
const showBaseCurrencyEquivalent = computed<boolean>(() => {
return !!(formData.value.exchange_rate && (props.store as Record<string, unknown>).showExchangeRate)
})
const baseCurrencyTotal = computed<number>(() => {
if (!formData.value.exchange_rate) return 0
return Math.round(total.value * Number(formData.value.exchange_rate))
})
const rules = {
name: {
required: helpers.withMessage(t('validation.required'), required),

View File

@@ -217,12 +217,20 @@
<BaseFormatMoney :amount="store.getTotal" :currency="defaultCurrency" />
</label>
</div>
<!-- Base currency equivalent -->
<div v-if="showBaseCurrencyEquivalent" class="flex items-center justify-end w-full mt-1">
<label class="text-xs text-muted">
<BaseFormatMoney :amount="baseCurrencyGrandTotal" :currency="companyCurrency" />
</label>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import TaxSelectPopup from './TaxSelectPopup.vue'
import { useCompanyStore } from '../../../stores/company.store'
import { generateClientId } from '../../../utils'
import type { Currency } from '../../../types/domain/currency'
import type { TaxType } from '../../../types/domain/tax'
@@ -245,6 +253,7 @@ const props = withDefaults(defineProps<Props>(), {
isLoading: false,
})
const companyStore = useCompanyStore()
const taxModal = ref<HTMLElement | null>(null)
const formData = computed<DocumentFormData>(() => {
@@ -263,6 +272,17 @@ const defaultCurrencySymbol = computed<string>(() => {
return (curr?.symbol as string) ?? '$'
})
const companyCurrency = computed(() => companyStore.selectedCompanyCurrency)
const showBaseCurrencyEquivalent = computed<boolean>(() => {
return !!(formData.value.exchange_rate && (props.store as Record<string, unknown>).showExchangeRate)
})
const baseCurrencyGrandTotal = computed<number>(() => {
if (!formData.value.exchange_rate) return 0
return Math.round(props.store.getTotal * Number(formData.value.exchange_rate))
})
watch(
() => formData.value.items,
() => setDiscount(),

View File

@@ -49,7 +49,7 @@
</template>
<script setup lang="ts">
import { watch, computed, ref, onBeforeUnmount } from 'vue'
import { watch, computed, ref, onMounted, onBeforeUnmount } from 'vue'
import { exchangeRateService } from '../../../api/services/exchange-rate.service'
import { useCompanyStore } from '../../../stores/company.store'
import { useGlobalStore } from '../../../stores/global.store'
@@ -79,6 +79,10 @@ const globalStore = useGlobalStore()
const hasActiveProvider = ref<boolean>(false)
const isFetching = ref<boolean>(false)
onMounted(() => {
globalStore.fetchCurrencies()
})
const formData = computed<DocumentFormData>(() => {
return props.store[props.storeProp] as DocumentFormData
})
@@ -139,12 +143,10 @@ function checkForActiveProvider(): void {
exchangeRateService
.getActiveProvider(Number(props.customerCurrency))
.then((res) => {
if (res.has_active_provider) {
hasActiveProvider.value = true
}
hasActiveProvider.value = res.hasActiveProvider
})
.catch(() => {
// Silently fail
hasActiveProvider.value = false
})
}
}
@@ -176,11 +178,7 @@ async function getCurrentExchangeRate(v: number | string | null | undefined): Pr
isFetching.value = true
try {
const res = await exchangeRateService.getRate(Number(v))
if (res && res.exchange_rate != null) {
formData.value.exchange_rate = res.exchange_rate
} else {
formData.value.exchange_rate = null
}
formData.value.exchange_rate = res.exchangeRate
} catch {
// Silently fail
} finally {