1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 12:01:57 +08:00

Fixing error when searching for product (#1009)

* Fixing error when searching for product

* Reducing calls to the Api

Co-authored-by: elsiosanchez <elsiossanches@gmail.com>
This commit is contained in:
Elsio Sanchez 2021-07-28 09:56:27 -04:00 committed by GitHub
parent 1a611b37b6
commit 6b7e03bc69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 240 additions and 54 deletions

View File

@ -379,10 +379,7 @@ export function getKeyLayout({ keyLayoutUuid }) {
export function getProductPriceList({ export function getProductPriceList({
searchValue, searchValue,
businessPartnerUuid, businessPartnerUuid,
validFrom,
posUuid, posUuid,
// Query
// criteria,
pageSize, pageSize,
pageToken pageToken
}) { }) {
@ -392,7 +389,6 @@ export function getProductPriceList({
params: { params: {
pos_uuid: posUuid, pos_uuid: posUuid,
search_value: searchValue, search_value: searchValue,
valid_from: validFrom,
business_partner_uuid: businessPartnerUuid, business_partner_uuid: businessPartnerUuid,
page_size: pageSize, page_size: pageSize,
page_token: pageToken page_token: pageToken

View File

@ -158,7 +158,6 @@ export default {
}, },
actionKeyPerformed(value) { actionKeyPerformed(value) {
// TODO: Delete for production // TODO: Delete for production
console.info('actionKeyPerformed ', value)
if (this.metadata.handleActionKeyPerformed) { if (this.metadata.handleActionKeyPerformed) {
this.$store.dispatch('notifyActionKeyPerformed', { this.$store.dispatch('notifyActionKeyPerformed', {
containerUuid: this.metadata.containerUuid, containerUuid: this.metadata.containerUuid,

View File

@ -21,7 +21,7 @@
<span> <span>
<b> <b>
{{ $t('form.pos.collect.convertAmount') }}: {{ $t('form.pos.collect.convertAmount') }}:
{{ formatPrice(amountConvertionTotal, displayCurrency) }} {{ formatPrice(amount / dayRate.divideRate, dayRate.iSOCode) }}
</b> </b>
</span> </span>
</div> </div>
@ -33,12 +33,20 @@
label-width="10px" label-width="10px"
style="float: right; display: flex; line-height: 10px;" style="float: right; display: flex; line-height: 10px;"
> >
<span v-for="(field, index) in fieldsList" :key="index"> <el-form-item :label="fieldsList[0].name">
<field-definition <el-select
:key="field.columnName" v-model="currentFieldCurrency"
:metadata-field="field" :placeholder="fieldsList[0].help"
/> @change="changeCurrency"
</span> >
<el-option
v-for="item in listCurrency"
:key="item.id"
:label="item.name"
:value="item.key"
/>
</el-select>
</el-form-item>
</el-form> </el-form>
</el-col> </el-col>
</el-row> </el-row>
@ -89,10 +97,23 @@ export default {
data() { data() {
return { return {
fieldsList: fieldsListConvertAmountCollection, fieldsList: fieldsListConvertAmountCollection,
amountConvertionTotal: this.amount amountConvertionTotal: this.amount,
currentFieldCurrency: '',
grandTotalConverted: {
divideRate: 1,
currencyTo: {
iSOCode: this.currency.iSOCode
}
}
} }
}, },
computed: { computed: {
listCurrency() {
return this.$store.getters.getCurrenciesList
},
convertionsList() {
return this.$store.state['pointOfSales/point/index'].conversionsList
},
displayCurrency() { displayCurrency() {
return this.$store.getters.getValueOfField({ return this.$store.getters.getValueOfField({
containerUuid: 'Collection-Convert-Amount', containerUuid: 'Collection-Convert-Amount',
@ -129,37 +150,33 @@ export default {
amountConvertion: 1 amountConvertion: 1
} }
}, },
dateRate() { dayRate() {
return this.$store.getters.getConvertionRate.find(currency => { if (this.isEmptyValue(this.currentFieldCurrency)) {
if (currency.id === this.typeCurrency) { return {
return currency currencyTo: this.currentPointOfSales.currentPriceList.currency,
divideRate: 1,
iSOCode: this.currency.iSOCode
}
}
const currency = this.listCurrency.find(currency => currency.key === this.currentFieldCurrency)
const convert = this.convertionsList.find(convert => {
if (!this.isEmptyValue(currency) &&
!this.isEmptyValue(convert.currencyTo) &&
currency.id === convert.currencyTo.id &&
this.currentPointOfSales.currentPriceList.currency.id !== currency.id
) {
return convert
} }
}) })
} if (!this.isEmptyValue(convert)) {
}, return convert
watch: { }
dateRate(value) { return {
if (value && !this.isEmptyValue(value.amountConvertion)) { currencyTo: this.currentPointOfSales.currentPriceList.currency,
this.amountConvertionTotal = this.amount / value.amountConvertion divideRate: 1,
} else { iSOCode: this.currency.iSOCode
this.amountConvertionTotal = this.amount
} }
} }
// currencyUuid(value) {
// const listCurrency = this.$store.getters.getConvertionRate.find(currency => {
// if (currency.uuid === value) {
// return currency
// }
// })
// if (listCurrency === undefined) {
// this.$store.dispatch('conversionDivideRate', {
// conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid,
// currencyFromUuid: this.pointOfSalesCurrency.uuid,
// conversionDate: this.formatDate(new Date()),
// currencyToUuid: value
// })
// }
// }
}, },
created() { created() {
this.defaultValueCurrency() this.defaultValueCurrency()
@ -189,6 +206,30 @@ export default {
columnName: 'C_Currency_ID', columnName: 'C_Currency_ID',
value: this.currency.id value: this.currency.id
}) })
},
amountConvert(currency) {
this.$store.dispatch('searchConversion', {
conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid,
currencyFromUuid: this.currentPointOfSales.priceList.currency.uuid,
currencyToUuid: currency.uuid
})
},
changeCurrency(value) {
this.currentFieldCurrency = value
const currency = this.listCurrency.find(currency => currency.key === value)
const convert = this.convertionsList.find(convert => {
if (!this.isEmptyValue(currency) && !this.isEmptyValue(convert.currencyTo) && currency.id === convert.currencyTo.id && this.currentPointOfSales.currentPriceList.currency.id !== currency.id) {
return convert
}
})
this.grandTotalConverted = convert
if (!this.isEmptyValue(currency) && this.isEmptyValue(convert) && currency.uuid !== this.currentPointOfSales.currentPriceList.currency.uuid) {
this.$store.dispatch('searchConversion', {
conversionTypeUuid: this.currentPointOfSales.conversionTypeUuid,
currencyFromUuid: this.currentPointOfSales.priceList.currency.uuid,
currencyToUuid: currency.uuid
})
}
} }
} }
} }

View File

@ -311,7 +311,7 @@ export default {
}, },
computed: { computed: {
listCurrency() { listCurrency() {
return this.$store.state['pointOfSales/point/index'].currenciesList return this.$store.getters.getCurrenciesList
}, },
convertionList() { convertionList() {
return this.$store.state['pointOfSales/point/index'].conversionsList return this.$store.state['pointOfSales/point/index'].conversionsList

View File

@ -330,7 +330,6 @@ import {
} from '@/api/ADempiere/form/point-of-sales.js' } from '@/api/ADempiere/form/point-of-sales.js'
import ModalDialog from '@/components/ADempiere/Dialog' import ModalDialog from '@/components/ADempiere/Dialog'
import posProcess from '@/utils/ADempiere/constants/posProcess' import posProcess from '@/utils/ADempiere/constants/posProcess'
import posMixin from '@/components/ADempiere/Form/VPOS/posMixin.js'
import orderLineMixin from '@/components/ADempiere/Form/VPOS/Order/orderLineMixin.js' import orderLineMixin from '@/components/ADempiere/Form/VPOS/Order/orderLineMixin.js'
export default { export default {
@ -341,8 +340,7 @@ export default {
ModalDialog ModalDialog
}, },
mixins: [ mixins: [
orderLineMixin, orderLineMixin
posMixin
], ],
props: { props: {
metadata: { metadata: {
@ -391,6 +389,50 @@ export default {
size() { size() {
const size = this.$store.getters.getWidthLeft const size = this.$store.getters.getWidthLeft
return 24 / size return 24 / size
},
currentPointOfSales() {
return this.$store.getters.posAttributes.currentPointOfSales
},
listPointOfSales() {
return this.$store.getters.posAttributes.pointOfSalesList
},
priceListPointOfSales() {
const list = this.$store.getters.posAttributes.currentPointOfSales.pricesList
if (this.isEmptyValue(list)) {
return []
}
return list
},
warehousesListPointOfSales() {
const list = this.$store.getters.posAttributes.currentPointOfSales.warehousesList
if (this.isEmptyValue(list)) {
return []
}
return list
},
ordersList() {
if (this.isEmptyValue(this.currentPointOfSales)) {
return []
}
return this.currentPointOfSales.listOrder
},
currentOrder() {
if (this.isEmptyValue(this.currentPointOfSales)) {
return {
documentType: {},
documentStatus: {
value: ''
},
totalLines: 0,
grandTotal: 0,
salesRepresentative: {},
businessPartner: {
value: '',
uuid: ''
}
}
}
return this.currentPointOfSales.currentOrder
} }
}, },
created() { created() {
@ -585,6 +627,62 @@ export default {
this.$store.dispatch('getProcessFromServer', { containerUuid: item.uuid, processId: item.id }) this.$store.dispatch('getProcessFromServer', { containerUuid: item.uuid, processId: item.id })
}) })
} }
},
changePos(posElement) {
this.$store.dispatch('setCurrentPOS', posElement)
this.newOrder()
},
newOrder() {
this.$router.push({
params: {
...this.$route.params
},
query: {
pos: this.currentPointOfSales.id
}
}).catch(() => {
}).finally(() => {
this.$store.commit('setListPayments', [])
const { templateBusinessPartner } = this.currentPointOfSales
this.$store.commit('updateValuesOfContainer', {
containerUuid: this.metadata.containerUuid,
attributes: [{
columnName: 'UUID',
value: undefined
},
{
columnName: 'ProductValue',
value: undefined
},
{
columnName: 'C_BPartner_ID',
value: templateBusinessPartner.id
},
{
columnName: 'DisplayColumn_C_BPartner_ID',
value: templateBusinessPartner.name
},
{
columnName: ' C_BPartner_ID_UUID',
value: templateBusinessPartner.uuid
}]
})
this.$store.dispatch('setOrder', {
documentType: {},
documentStatus: {
value: ''
},
totalLines: 0,
grandTotal: 0,
salesRepresentative: {},
businessPartner: {
value: '',
uuid: ''
}
})
this.$store.commit('setShowPOSCollection', false)
this.$store.dispatch('listOrderLine', [])
})
} }
} }
} }

View File

@ -684,7 +684,6 @@ export default {
formatPrice, formatPrice,
formatQuantity, formatQuantity,
focusPin() { focusPin() {
console.log(this.$refs)
this.$refs.pin.focus() this.$refs.pin.focus()
}, },
openPin(pin) { openPin(pin) {

View File

@ -33,12 +33,11 @@
:metadata-field="field" :metadata-field="field"
/> />
</el-form> </el-form>
<el-table <el-table
ref="listProducto" ref="listProducto"
v-shortkey="shortsKey" v-shortkey="shortsKey"
v-loading="!productPrice.isLoaded" v-loading="isEmptyValue(listWithPrice) || isLoadedServer"
:data="listWithPrice" :data="localTableSearch(listWithPrice)"
border border
fit fit
height="450" height="450"
@ -112,6 +111,7 @@ export default {
return { return {
defaultMaxPagination: 50, defaultMaxPagination: 50,
fieldsList: fieldsListProductPrice, fieldsList: fieldsListProductPrice,
isLoadedServer: false,
isCustomForm: true, isCustomForm: true,
timeOut: null timeOut: null
} }
@ -145,6 +145,12 @@ export default {
isReadyFromGetData() { isReadyFromGetData() {
const { isLoaded, isReload } = this.productPrice const { isLoaded, isReload } = this.productPrice
return (!isLoaded || isReload) // && this.isShowProductsPriceList return (!isLoaded || isReload) // && this.isShowProductsPriceList
},
searchValue() {
return this.$store.getters.getValueOfField({
containerUuid: this.metadata.containerUuid,
columnName: 'ProductValue'
})
} }
}, },
created() { created() {
@ -161,6 +167,37 @@ export default {
}, },
methods: { methods: {
formatPrice, formatPrice,
localTableSearch(listWithPrice) {
let filtersProduct = []
if (!this.isEmptyValue(this.searchValue)) {
filtersProduct = listWithPrice.filter(data => data.product.name.toLowerCase().includes(this.searchValue.toLowerCase()) || data.product.value.toLowerCase().includes(this.searchValue.toLowerCase()))
if (!this.isEmptyValue(filtersProduct)) {
return filtersProduct
}
this.isLoadedServer = true
this.timeOut = setTimeout(() => {
this.$store.dispatch('listProductPriceFromServer', {
containerUuid: 'Products-Price-List',
pageNumber: 1,
searchValue: this.searchValue
})
.then(() => {
const recordsList = this.listWithPrice
if (this.isEmptyValue(recordsList)) {
this.$message({
message: 'Sin resultados coincidentes con la busqueda',
type: 'info',
showClose: true
})
}
this.isLoadedServer = false
return recordsList
})
}, 2000)
}
return listWithPrice
},
keyAction(event) { keyAction(event) {
switch (event.srcKey) { switch (event.srcKey) {
case 'refreshList': case 'refreshList':
@ -215,6 +252,12 @@ export default {
this.timeOut = setTimeout(() => { this.timeOut = setTimeout(() => {
this.$store.commit('setIsReloadProductPrice') this.$store.commit('setIsReloadProductPrice')
}, 1000) }, 1000)
} else if (mutation.type === 'addActionKeyPerformed' && mutation.payload.containerUuid === this.metadata.containerUuid) {
this.$store.dispatch('listProductPriceFromServer', {
containerUuid: mutation.payload.containerUuid,
pageNumber: 1,
searchValue: mutation.payload.value
})
} }
}) })
}, },

View File

@ -346,7 +346,8 @@ export default {
} }
findProduct({ findProduct({
searchValue: searchProduct, searchValue: searchProduct,
priceListUuid: this.curretnPriceList.uuid priceListUuid: this.curretnPriceList.uuid,
posUuid: this.currentPointOfSales.uuid
}) })
.then(productPrice => { .then(productPrice => {
this.product = productPrice.product this.product = productPrice.product
@ -471,6 +472,10 @@ export default {
} else if (mutation.type === 'addActionPerformed') { } else if (mutation.type === 'addActionPerformed') {
switch (mutation.payload.columnName) { switch (mutation.payload.columnName) {
case 'QtyEntered': case 'QtyEntered':
if (!this.isEmptyValue(this.$store.state['pointOfSales/orderLine/index'].line)) {
this.updateOrderLine(mutation.payload)
}
break
case 'PriceEntered': case 'PriceEntered':
case 'Discount': case 'Discount':
if (this.isPosRequiredPin && !this.isEmptyValue(this.$store.state['pointOfSales/orderLine/index'].line)) { if (this.isPosRequiredPin && !this.isEmptyValue(this.$store.state['pointOfSales/orderLine/index'].line)) {

View File

@ -140,6 +140,9 @@ export default {
return state.currentDocumentTypePos return state.currentDocumentTypePos
} }
return {} return {}
} },
// Current POS, it can be s // Current POS, it can be s
getCurrenciesList: (state) => {
return state.currenciesList
}
} }

View File

@ -35,6 +35,7 @@ export default {
currentWarehousePos: {}, currentWarehousePos: {},
currentDocumentTypePos: {}, currentDocumentTypePos: {},
listCurrency: [], listCurrency: [],
currenciesList: [],
conversionsList: [], conversionsList: [],
currentPointOfSales: {}, currentPointOfSales: {},
showPOSOptions: false, showPOSOptions: false,

View File

@ -71,7 +71,7 @@ export default {
return new Promise(resolve => { return new Promise(resolve => {
getProductPriceList({ getProductPriceList({
searchValue, searchValue,
posUuid: currentPointOfSales.uuid, posUuid,
businessPartnerUuid, businessPartnerUuid,
pageToken pageToken
}).then(responseProductPrice => { }).then(responseProductPrice => {
@ -103,9 +103,10 @@ export default {
listProductPriceFromServerProductInfo({ state, commit, rootGetters }, { listProductPriceFromServerProductInfo({ state, commit, rootGetters }, {
containerUuid = 'Products-Price-List-ProductInfo', containerUuid = 'Products-Price-List-ProductInfo',
pageNumber, // 1 pageNumber, // 1
searchValue searchValue,
currentPOS
}) { }) {
const posUuid = rootGetters.posAttributes.currentPointOfSales.uuid const posUuid = isEmptyValue(currentPOS) ? rootGetters.posAttributes.currentPointOfSales.uuid : currentPOS.uuid
if (isEmptyValue(posUuid)) { if (isEmptyValue(posUuid)) {
const message = 'Sin punto de venta seleccionado' const message = 'Sin punto de venta seleccionado'
showMessage({ showMessage({
@ -142,7 +143,7 @@ export default {
return new Promise(resolve => { return new Promise(resolve => {
getProductPriceList({ getProductPriceList({
searchValue, searchValue,
posUuid: rootGetters.currentPointOfSales.uuid, posUuid: posUuid,
businessPartnerUuid, businessPartnerUuid,
pageToken pageToken
}).then(responseProductPrice => { }).then(responseProductPrice => {