From 4c49b201441790aebcb345dac5c2c86fdf98b989 Mon Sep 17 00:00:00 2001
From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com>
Date: Fri, 23 Apr 2021 18:04:26 -0400
Subject: [PATCH] Converting for payment methods (#749)
* Fixes: #736
* minimal changes
* minimal changes
Co-authored-by: Elsio Sanchez
+ Tasa del Día: + + {{ + dateRate.iSOCode + }} + {{ + formatConversionCurrenty(dateRate.amountConvertion) + }} + +
{{ $t('form.pos.order.order') }}: {{ currentOrder.documentNo }}
{{ $t('form.pos.order.date') }}: @@ -395,29 +395,29 @@ export default { return this.isDisabled ? this.$t('form.pos.order.collections') : this.$t('form.pos.order.collect') } }, - watch: { - currencyUuid(value) { - if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { - this.$store.dispatch('conversionDivideRate', { - conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, - currencyFromUuid: this.pointOfSalesCurrency.uuid, - currencyToUuid: value - }) - } - }, - converCurrency(value) { - if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { - this.$store.dispatch('conversionMultiplyRate', { - containerUuid: 'Order', - conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, - currencyFromUuid: this.pointOfSalesCurrency.uuid, - currencyToUuid: value - }) - } else { - this.$store.commit('currencyMultiplyRate', 1) - } - } - }, + // watch: { + // currencyUuid(value) { + // if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { + // this.$store.dispatch('conversionDivideRate', { + // conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, + // currencyFromUuid: this.pointOfSalesCurrency.uuid, + // currencyToUuid: value + // }) + // } + // }, + // converCurrency(value) { + // if (!this.isEmptyValue(value) && !this.isEmptyValue(this.currentPointOfSales)) { + // this.$store.dispatch('conversionMultiplyRate', { + // containerUuid: 'Order', + // conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid, + // currencyFromUuid: this.pointOfSalesCurrency.uuid, + // currencyToUuid: value + // }) + // } else { + // this.$store.commit('currencyMultiplyRate', 1) + // } + // } + // }, mounted() { if (!this.isEmptyValue(this.$route.query.action)) { this.$store.dispatch('reloadOrder', { orderUuid: this.$route.query.action }) diff --git a/src/components/ADempiere/Form/VPOS/posMixin.js b/src/components/ADempiere/Form/VPOS/posMixin.js index 4d1ceed6..dc7691fe 100644 --- a/src/components/ADempiere/Form/VPOS/posMixin.js +++ b/src/components/ADempiere/Form/VPOS/posMixin.js @@ -82,12 +82,16 @@ export default { pointOfSalesCurrency() { // const currency = this.currentPointOfSales if (!this.isEmptyValue(this.currentPointOfSales.priceList)) { - return this.currentPointOfSales.priceList.currency + return { + ...this.currentPointOfSales.priceList.currency, + amountConvertion: 1 + } } return { uuid: '', iSOCode: '', - curSymbol: '' + curSymbol: '', + amountConvertion: 1 } }, listPointOfSales() { diff --git a/src/store/modules/ADempiere/pointOfSales/payments/actions.js b/src/store/modules/ADempiere/pointOfSales/payments/actions.js index d4f5a175..0191b2fb 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/actions.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/actions.js @@ -111,18 +111,30 @@ export default { const payment = state.paymentBox payment.splice(0) }, - conversionDivideRate({ commit }, params) { + conversionDivideRate({ commit, dispatch }, params) { + console.log('conversionDivideRate') requestGetConversionRate({ conversionTypeUuid: params.conversionTypeUuid, currencyFromUuid: params.currencyFromUuid, - currencyToUuid: params.currencyToUuid + currencyToUuid: params.currencyToUuid, + conversionDate: params.conversionDate }) .then(response => { commit('setFieldCurrency', response.currencyTo) + if (!isEmptyValue(response.currencyTo)) { + const currency = { + ...response.currencyTo, + amountConvertion: response.divideRate + } + dispatch('addRateConvertion', currency) + } const divideRate = isEmptyValue(response.divideRate) ? 1 : response.divideRate + const multiplyRate = isEmptyValue(response.multiplyRate) ? 1 : response.multiplyRate if (params.containerUuid === 'Collection') { + commit('currencyMultiplyRateCollection', multiplyRate) commit('currencyDivideRateCollection', divideRate) } else { + commit('currencyMultiplyRate', multiplyRate) commit('currencyDivideRateCollection', divideRate) } }) @@ -135,6 +147,9 @@ export default { }) }) }, + addRateConvertion({ commit, state, getters }, currency) { + commit('conversionRate', currency) + }, conversionMultiplyRate({ commit }, { containerUuid, conversionTypeUuid, @@ -149,7 +164,7 @@ export default { // conversionDate }) .then(response => { - const multiplyRate = isEmptyValue(response.multiplyRate) ? 0 : response.multiplyRate + const multiplyRate = isEmptyValue(response.multiplyRate) ? 1 : response.multiplyRate if (containerUuid === 'Collection') { commit('currencyMultiplyRateCollection', multiplyRate) } else { diff --git a/src/store/modules/ADempiere/pointOfSales/payments/getters.js b/src/store/modules/ADempiere/pointOfSales/payments/getters.js index 7c513693..31c5e7d1 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/getters.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/getters.js @@ -45,5 +45,8 @@ export default { }, getFieldCuerrency: (state) => { return state.fieldCurrency + }, + getConvertionRate: (state) => { + return state.convertionRate } } diff --git a/src/store/modules/ADempiere/pointOfSales/payments/mutations.js b/src/store/modules/ADempiere/pointOfSales/payments/mutations.js index 1b77ce17..d92ce0ed 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/mutations.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/mutations.js @@ -42,6 +42,19 @@ export default { setConvertionPayment(state, convertion) { state.convertion = convertion }, + conversionRate(state, currency) { + const listCurrent = state.convertionRate.find(element => { + if (element.id === currency.id) { + return element + } + }) + if (listCurrent === undefined) { + state.convertionRate.push(currency) + } + }, + resetConversionRate(state, currency) { + state.convertionRate = currency + }, setFieldCurrency(state, currency) { state.fieldCurrency = currency } diff --git a/src/store/modules/ADempiere/pointOfSales/payments/state.js b/src/store/modules/ADempiere/pointOfSales/payments/state.js index c320d3df..70f935ea 100644 --- a/src/store/modules/ADempiere/pointOfSales/payments/state.js +++ b/src/store/modules/ADempiere/pointOfSales/payments/state.js @@ -29,5 +29,6 @@ export default { }, currency: [], convertion: {}, - fieldCurrency: {} + fieldCurrency: {}, + convertionRate: [] } diff --git a/src/store/modules/ADempiere/pointOfSales/point/actions.js b/src/store/modules/ADempiere/pointOfSales/point/actions.js index 72b5fd78..c31a6ec7 100644 --- a/src/store/modules/ADempiere/pointOfSales/point/actions.js +++ b/src/store/modules/ADempiere/pointOfSales/point/actions.js @@ -73,6 +73,7 @@ export default { } }, () => {}) + commit('resetConversionRate', []) commit('setIsReloadKeyLayout') commit('setIsReloadProductPrice') commit('setIsReloadListOrders') diff --git a/src/utils/ADempiere/apiConverts/core.js b/src/utils/ADempiere/apiConverts/core.js index 84bf8cda..767811ce 100644 --- a/src/utils/ADempiere/apiConverts/core.js +++ b/src/utils/ADempiere/apiConverts/core.js @@ -157,7 +157,7 @@ export function convertCurrency(currencyToConvert) { id: currencyToConvert.id, uuid: currencyToConvert.uuid, iSOCode: currencyToConvert.iso_code, - curSymbol: currencyToConvert.cur_symbol, + curSymbol: currencyToConvert.currency_symbol, description: currencyToConvert.description, standardPrecision: currencyToConvert.standard_precision, costingPrecision: currencyToConvert.costing_precision diff --git a/src/utils/ADempiere/globalMethods.js b/src/utils/ADempiere/globalMethods.js index a2bd7bdc..df423dc7 100644 --- a/src/utils/ADempiere/globalMethods.js +++ b/src/utils/ADempiere/globalMethods.js @@ -23,5 +23,6 @@ export { clearVariables, currencyFind, tenderTypeFind, + formatConversionCurrenty, typeValue } from '@/utils/ADempiere/valueUtils.js' diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index 373e2007..7ed18b4e 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -546,3 +546,15 @@ export function tenderTypeFind({ export function clearVariables() { partialValue = '' } +export function formatConversionCurrenty(params) { + let exponential, expre + const number = params.toString() + if (params > 0) { + if (number.includes('e')) { + expre = number.split('-') + exponential = params.toFixed(expre[1]) + return exponential + } + } + return params +}