From 1ac6300576251e24f6871773d6f4366ce39e0cea Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Thu, 23 Dec 2021 00:05:00 -0400 Subject: [PATCH] fix: Default value send multiple request. --- .../ADempiere/Field/mixin/mixinField.js | 4 +- src/store/modules/ADempiere/data/actions.js | 2 +- .../modules/ADempiere/defaultValueManager.js | 26 ++++++++-- .../ADempiere/dictionary/window/getters.js | 49 +++++++++++++++++++ src/store/modules/ADempiere/panel/actions.js | 2 +- src/store/modules/ADempiere/persistence.js | 42 +++++++++++----- src/views/ADempiere/Window/MultiTabWindow.vue | 28 ++++++----- 7 files changed, 120 insertions(+), 33 deletions(-) diff --git a/src/components/ADempiere/Field/mixin/mixinField.js b/src/components/ADempiere/Field/mixin/mixinField.js index 708962790d5..8e2d8b07075 100644 --- a/src/components/ADempiere/Field/mixin/mixinField.js +++ b/src/components/ADempiere/Field/mixin/mixinField.js @@ -93,7 +93,7 @@ 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, @@ -101,7 +101,7 @@ export default { }) 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, diff --git a/src/store/modules/ADempiere/data/actions.js b/src/store/modules/ADempiere/data/actions.js index f483125eb20..92416edd831 100644 --- a/src/store/modules/ADempiere/data/actions.js +++ b/src/store/modules/ADempiere/data/actions.js @@ -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 diff --git a/src/store/modules/ADempiere/defaultValueManager.js b/src/store/modules/ADempiere/defaultValueManager.js index 86cecd8df5a..538b99966ee 100644 --- a/src/store/modules/ADempiere/defaultValueManager.js +++ b/src/store/modules/ADempiere/defaultValueManager.js @@ -24,6 +24,7 @@ import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js' import { parseContext } from '@/utils/ADempiere/contextUtils' const initState = { + inRequest: new Map(), storedDefaultValue: {} } @@ -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, @@ -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) + }) }) } }, diff --git a/src/store/modules/ADempiere/dictionary/window/getters.js b/src/store/modules/ADempiere/dictionary/window/getters.js index ca568d68339..157c082b886 100644 --- a/src/store/modules/ADempiere/dictionary/window/getters.js +++ b/src/store/modules/ADempiere/dictionary/window/getters.js @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +// utils and helpers methods import { isEmptyValue } from '@/utils/ADempiere/valueUtils' +import { isDisplayedField, isMandatoryField } from '@/utils/ADempiere/dictionary/window.js' /** * Dictionary Window Getters @@ -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 } } diff --git a/src/store/modules/ADempiere/panel/actions.js b/src/store/modules/ADempiere/panel/actions.js index 2f3962a6681..d73ae4d5c08 100644 --- a/src/store/modules/ADempiere/panel/actions.js +++ b/src/store/modules/ADempiere/panel/actions.js @@ -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 diff --git a/src/store/modules/ADempiere/persistence.js b/src/store/modules/ADempiere/persistence.js index da06d286b17..28ac3e977b8 100644 --- a/src/store/modules/ADempiere/persistence.js +++ b/src/store/modules/ADempiere/persistence.js @@ -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 . + +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: { @@ -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 => { @@ -88,7 +107,7 @@ const persistence = { }) }, - flushPersistenceQueue({ getters, dispatch }, { + flushPersistenceQueue({ getters }, { containerUuid, tableName, recordUuid @@ -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({ diff --git a/src/views/ADempiere/Window/MultiTabWindow.vue b/src/views/ADempiere/Window/MultiTabWindow.vue index eac3c833da9..a56e72912e1 100644 --- a/src/views/ADempiere/Window/MultiTabWindow.vue +++ b/src/views/ADempiere/Window/MultiTabWindow.vue @@ -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({