Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Default value send multiple request. #1449

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/ADempiere/Field/mixin/mixinField.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ export default {
},

async created() {
if (this.metadata.isSQLValue && (this.isEmptyValue(this.metadata.value) || this.metadata.value.isSQL)) {
if (this.metadata.isSQLValue && this.isEmptyValue(this.value)) {
let value = this.$store.getters.getStoredDefaultValue({
parentUuid: this.metadata.parentUuid,
containerUuid: this.metadata.containerUuid,
query: this.metadata.defaultValue
})

if (this.isEmptyValue(value)) {
value = await this.$store.dispatch('getValueBySQL', {
value = await this.$store.dispatch('getDefaultValue', {
parentUuid: this.metadata.parentUuid,
containerUuid: this.metadata.containerUuid,
columnName: this.metadata.columnName,
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/ADempiere/data/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const actions = {
typeValue(valueGetDisplayColumn) === 'OBJECT' &&
valueGetDisplayColumn.isSQL) {
// get value from Query
valueGetDisplayColumn = await dispatch('getValueBySQL', {
valueGetDisplayColumn = await dispatch('getDefaultValue', {
parentUuid,
containerUuid,
query: itemField.defaultValue
Expand Down
26 changes: 21 additions & 5 deletions src/store/modules/ADempiere/defaultValueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { parseContext } from '@/utils/ADempiere/contextUtils'

const initState = {
inRequest: new Map(),
storedDefaultValue: {}
}

Expand All @@ -49,29 +50,40 @@ const defaultValueManager = {
/**
* @param {string} parentUuid
* @param {string} containerUuid
* @param {string} columnName
* @param {string} query
*/
getValueBySQL({ commit, rootGetters }, {
getDefaultValue({ state, commit, rootGetters }, {
parentUuid,
containerUuid,
columnName,
query
}) {
// TODO: Change to promise all
return new Promise(resolve => {
let parsedQuery = query
if (query.includes('@')) {
parsedQuery = parseContext({
const context = parseContext({
parentUuid,
containerUuid,
isSQL: true,
value: query
}).query
})
if (context.isError) {
return undefined
}
parsedQuery = context.query
}

const clientId = rootGetters.getPreferenceClientId
const key = `${clientId}_${parsedQuery}`

// if it is the same request, it is not made
if (state.inRequest.get(key)) {
return
}
state.inRequest.set(key, true)
requestDefaultValue(parsedQuery)
.then(valueResponse => {
const clientId = rootGetters.getPreferenceClientId
commit('setDefaultValue', {
clientId,
parsedQuery,
Expand All @@ -90,6 +102,10 @@ const defaultValueManager = {
.catch(error => {
console.warn(`Error getting default value from server. Error code ${error.code}: ${error.message}.`)
})
.finally(() => {
// current request finalized
state.inRequest.set(key, false)
})
})
}
},
Expand Down
49 changes: 49 additions & 0 deletions src/store/modules/ADempiere/dictionary/window/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// utils and helpers methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { isDisplayedField, isMandatoryField } from '@/utils/ADempiere/dictionary/window.js'

/**
* Dictionary Window Getters
Expand Down Expand Up @@ -64,5 +66,52 @@ export default {
const window = getters.getStoredWindow(windowUuid)

return window.currentTabChild
},

/**
* Determinate if panel is ready to send, all fields mandatory and displayed with values
* @param {string} containerUuid
* @param {object} row, data to compare if is table
* @returns {object}
*/
getTabFieldsEmptyMandatory: (state, getters, rootState, rootGetters) => ({
parentUuid,
containerUuid,
fieldsList,
formatReturn = 'name'
}) => {
if (isEmptyValue(fieldsList)) {
fieldsList = getters.getStoredFieldsFromTab(parentUuid, containerUuid)
}

const fieldsEmpty = fieldsList.filter(fieldItem => {
const isMandatory = isMandatoryField(fieldItem)
const isDisplayed = isDisplayedField(fieldItem)

if (!(isDisplayed && isMandatory)) {
return false
}

const value = rootGetters.getValueOfField({
containerUuid,
columnName: fieldItem.columnName
})

if (!isEmptyValue(value)) {
return false
}

// displayed or madatory and empty
return true
})

if (formatReturn) {
return fieldsEmpty.map(fieldItem => {
// fieldItem.name by default
return fieldItem[formatReturn]
})
}

return fieldsEmpty
}
}
2 changes: 1 addition & 1 deletion src/store/modules/ADempiere/panel/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ const actions = {
value: fieldDependent.defaultValue
}).query
if (defaultValue !== fieldDependent.parsedDefaultValue) {
const newValue = await dispatch('getValueBySQL', {
const newValue = await dispatch('getDefaultValue', {
parentUuid: field.parentUuid,
containerUuid: field.containerUuid,
query: defaultValue
Expand Down
42 changes: 31 additions & 11 deletions src/store/modules/ADempiere/persistence.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
// ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
// Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A.
// Contributor(s): Yamel Senih ysenih@erpya.com www.erpya.com
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import router from '@/router'
import language from '@/lang'

// constants
import { LOG_COLUMNS_NAME_LIST } from '@/utils/ADempiere/constants/systemColumns'

// api request methods
import {
createEntity,
updateEntity
} from '@/api/ADempiere/common/persistence.js'

// utils and helper methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { LOG_COLUMNS_NAME_LIST } from '@/utils/ADempiere/constants/systemColumns'
import language from '@/lang'
import { showMessage } from '@/utils/ADempiere/notification.js'
import router from '@/router'

const persistence = {
state: {
Expand Down Expand Up @@ -51,13 +73,10 @@ const persistence = {
value
})

// TODO: Add dictonary getter
const fieldsList = getters.getStoredFieldsFromTab(parentUuid, containerUuid)

const emptyFields = getters.getFieldsListEmptyMandatory({
const emptyFields = getters.getTabFieldsEmptyMandatory({
parentUuid,
containerUuid,
formatReturn: false,
fieldsList
formatReturn: false
}).filter(itemField => {
return !LOG_COLUMNS_NAME_LIST.includes(itemField.columnName)
}).map(itemField => {
Expand Down Expand Up @@ -88,7 +107,7 @@ const persistence = {
})
},

flushPersistenceQueue({ getters, dispatch }, {
flushPersistenceQueue({ getters }, {
containerUuid,
tableName,
recordUuid
Expand All @@ -99,7 +118,8 @@ const persistence = {
// omit send to server (to create or update) columns manage by backend
return !LOG_COLUMNS_NAME_LIST.includes(itemField.columnName)
})
if (attributesList) {

if (!isEmptyValue(attributesList)) {
if (!isEmptyValue(recordUuid)) {
// Update existing entity
updateEntity({
Expand Down
28 changes: 15 additions & 13 deletions src/views/ADempiere/Window/MultiTabWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,21 @@ export default defineComponent({
})
return
}

root.$router.push({
name: root.$route.name,
query: {
...root.$route.query,
action: row.UUID
},
params: {
...root.$router.params,
tableName,
recordId: row[`${tableName}_ID`]
}
}, () => {})
const tab = root.$store.getters.getStoredTab(parentUuid, containerUuid)
if (tab.isParentTab) {
root.$router.push({
name: root.$route.name,
query: {
...root.$route.query,
action: row.UUID
},
params: {
...root.$router.params,
tableName,
recordId: row[`${tableName}_ID`]
}
}, () => {})
}

const fieldsList = root.$store.getters.getStoredFieldsFromTab(parentUuid, containerUuid)
const defaultValues = root.$store.getters.getParsedDefaultValues({
Expand Down