From 4766b1164a81fb5d02c8b8f82cbc8b5f8200ca57 Mon Sep 17 00:00:00 2001 From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com> Date: Tue, 18 May 2021 17:16:52 -0400 Subject: [PATCH] Fix Price Checking (#854) * Fix Price Checking * Update request.js * valide search value * minimal changes Co-authored-by: elsiosanchez Co-authored-by: Edwin Betancourt --- src/api/ADempiere/form/price-checking.js | 5 ++++- .../ADempiere/Form/PriceChecking/fieldsList.js | 1 + .../ADempiere/Form/PriceChecking/index.vue | 18 +++++++++++------- src/utils/ADempiere/request.js | 12 ++++++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/api/ADempiere/form/price-checking.js b/src/api/ADempiere/form/price-checking.js index 49d12921..8a32dd9f 100644 --- a/src/api/ADempiere/form/price-checking.js +++ b/src/api/ADempiere/form/price-checking.js @@ -15,6 +15,7 @@ // along with this program. If not, see . // Get Instance for connectionimport { +import { isEmptyValue } from '@/utils/ADempiere' import { request } from '@/utils/ADempiere/request' // List Point of sales @@ -44,7 +45,9 @@ export function requestGetProductPrice({ }) .then(productPriceResponse => { const { convertProductPrice } = require('@/utils/ADempiere/apiConverts/core.js') - + if (isEmptyValue(productPriceResponse)) { + return productPriceResponse + } return convertProductPrice(productPriceResponse) }) } diff --git a/src/components/ADempiere/Form/PriceChecking/fieldsList.js b/src/components/ADempiere/Form/PriceChecking/fieldsList.js index a57dd212..766935b6 100644 --- a/src/components/ADempiere/Form/PriceChecking/fieldsList.js +++ b/src/components/ADempiere/Form/PriceChecking/fieldsList.js @@ -18,6 +18,7 @@ export default [ // Product Code { elementColumnName: 'ProductValue', + columnName: 'ProductValue', isFromDictionary: true, overwriteDefinition: { size: 24, diff --git a/src/components/ADempiere/Form/PriceChecking/index.vue b/src/components/ADempiere/Form/PriceChecking/index.vue index 4db5294f..40cbfc4c 100644 --- a/src/components/ADempiere/Form/PriceChecking/index.vue +++ b/src/components/ADempiere/Form/PriceChecking/index.vue @@ -152,9 +152,6 @@ export default { }, mounted() { this.getImage() - setTimeout(() => { - this.focusProductValue() - }, 1000) }, beforeDestroy() { this.unsubscribe() @@ -197,7 +194,10 @@ export default { formatPrice, subscribeChanges() { return this.$store.subscribe((mutation, state) => { - if ((mutation.type === 'addActionKeyPerformed') && mutation.payload.columnName === 'ProductValue') { + if ((mutation.type === 'currentPointOfSales') || (mutation.type === 'setListProductPrice') || (mutation.type === 'addFocusLost')) { + this.focusProductValue() + } + if ((mutation.type === 'addActionKeyPerformed') && mutation.payload.columnName === 'ProductValue' && (this.productPrice.upc !== mutation.payload.value)) { // cleans all values except column name 'ProductValue' this.search = mutation.payload.value if (!this.isEmptyValue(this.search) && this.search.length >= 4) { @@ -229,7 +229,8 @@ export default { taxRate: rate, taxName: taxRate.name, taxIndicator: taxRate.taxIndicator, - taxAmt: this.getTaxAmount(priceBase, rate) + taxAmt: this.getTaxAmount(priceBase, rate), + upc: product.upc } }) .catch(() => { @@ -250,9 +251,13 @@ export default { } }) } - } else if ((mutation.type === 'updateValueOfField') && (mutation.payload.columnName === 'ProductValue') && !this.isEmptyValue(mutation.payload.value)) { + } else if ((mutation.type === 'updateValueOfField') && (mutation.payload.columnName === 'ProductValue') && !this.isEmptyValue(mutation.payload.value) && (this.productPrice.upc !== mutation.payload.value)) { clearTimeout(this.timeOut) this.timeOut = setTimeout(() => { + let value = mutation.payload.value + if (typeof value[value.length - 1] === 'string') { + value = mutation.payload.value.slice(0, -1) + } requestGetProductPrice({ searchValue: mutation.payload.value, priceListUuid: this.currentPoint.priceList.uuid @@ -262,7 +267,6 @@ export default { const { product, taxRate, priceStandard: priceBase } = productPrice const { rate } = taxRate const { imageURL: image } = product - this.productPrice = { currency: productPrice.currency, image, diff --git a/src/utils/ADempiere/request.js b/src/utils/ADempiere/request.js index 41c5d52a..b7e98a0e 100644 --- a/src/utils/ADempiere/request.js +++ b/src/utils/ADempiere/request.js @@ -37,9 +37,13 @@ export function request(requestValues) { } requestValues.params.token = getToken() requestValues.params.language = getLanguage() || 'en_US' - return new Promise(resolve => { - requestAPI(requestValues).then(response => { - resolve(response.result) - }) + return new Promise((resolve, reject) => { + requestAPI(requestValues) + .then(response => { + resolve(response.result) + }) + .catch(response => { + reject(response) + }) }) }