1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-07 18:25:45 +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({
searchValue,
businessPartnerUuid,
validFrom,
posUuid,
// Query
// criteria,
pageSize,
pageToken
}) {
@ -392,7 +389,6 @@ export function getProductPriceList({
params: {
pos_uuid: posUuid,
search_value: searchValue,
valid_from: validFrom,
business_partner_uuid: businessPartnerUuid,
page_size: pageSize,
page_token: pageToken

View File

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

View File

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

View File

@ -330,7 +330,6 @@ import {
} from '@/api/ADempiere/form/point-of-sales.js'
import ModalDialog from '@/components/ADempiere/Dialog'
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'
export default {
@ -341,8 +340,7 @@ export default {
ModalDialog
},
mixins: [
orderLineMixin,
posMixin
orderLineMixin
],
props: {
metadata: {
@ -391,6 +389,50 @@ export default {
size() {
const size = this.$store.getters.getWidthLeft
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() {
@ -585,6 +627,62 @@ export default {
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,
formatQuantity,
focusPin() {
console.log(this.$refs)
this.$refs.pin.focus()
},
openPin(pin) {

View File

@ -33,12 +33,11 @@
:metadata-field="field"
/>
</el-form>
<el-table
ref="listProducto"
v-shortkey="shortsKey"
v-loading="!productPrice.isLoaded"
:data="listWithPrice"
v-loading="isEmptyValue(listWithPrice) || isLoadedServer"
:data="localTableSearch(listWithPrice)"
border
fit
height="450"
@ -112,6 +111,7 @@ export default {
return {
defaultMaxPagination: 50,
fieldsList: fieldsListProductPrice,
isLoadedServer: false,
isCustomForm: true,
timeOut: null
}
@ -145,6 +145,12 @@ export default {
isReadyFromGetData() {
const { isLoaded, isReload } = this.productPrice
return (!isLoaded || isReload) // && this.isShowProductsPriceList
},
searchValue() {
return this.$store.getters.getValueOfField({
containerUuid: this.metadata.containerUuid,
columnName: 'ProductValue'
})
}
},
created() {
@ -161,6 +167,37 @@ export default {
},
methods: {
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) {
switch (event.srcKey) {
case 'refreshList':
@ -215,6 +252,12 @@ export default {
this.timeOut = setTimeout(() => {
this.$store.commit('setIsReloadProductPrice')
}, 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({
searchValue: searchProduct,
priceListUuid: this.curretnPriceList.uuid
priceListUuid: this.curretnPriceList.uuid,
posUuid: this.currentPointOfSales.uuid
})
.then(productPrice => {
this.product = productPrice.product
@ -471,6 +472,10 @@ export default {
} else if (mutation.type === 'addActionPerformed') {
switch (mutation.payload.columnName) {
case 'QtyEntered':
if (!this.isEmptyValue(this.$store.state['pointOfSales/orderLine/index'].line)) {
this.updateOrderLine(mutation.payload)
}
break
case 'PriceEntered':
case 'Discount':
if (this.isPosRequiredPin && !this.isEmptyValue(this.$store.state['pointOfSales/orderLine/index'].line)) {

View File

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

View File

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

View File

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