From 2702d28ef21367cb118d7f319d237e82c5a94894 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Sun, 30 Jan 2022 00:01:32 -0400 Subject: [PATCH 1/2] fix: Set correct boolean value. --- src/store/modules/ADempiere/panel/getters.js | 42 +++++++------------- src/utils/ADempiere/contextUtils.js | 19 ++++++--- src/utils/ADempiere/dictionaryUtils.js | 18 +++++++-- src/utils/ADempiere/valueUtils.js | 21 ++++++++++ 4 files changed, 64 insertions(+), 36 deletions(-) diff --git a/src/store/modules/ADempiere/panel/getters.js b/src/store/modules/ADempiere/panel/getters.js index 48bbf7f2a39..2d68757c8d9 100644 --- a/src/store/modules/ADempiere/panel/getters.js +++ b/src/store/modules/ADempiere/panel/getters.js @@ -19,7 +19,6 @@ import { parsedValueComponent } from '@/utils/ADempiere/valueUtils.js' import { - ACCOUNTING_COLUMNS, LOG_COLUMNS_NAME_LIST } from '@/utils/ADempiere/constants/systemColumns' import { @@ -290,39 +289,26 @@ const getters = { let attributesList = fieldsList .map(fieldItem => { const { columnName, defaultValue } = fieldItem - let isSQL = false - let parsedDefaultValue = fieldItem.parsedDefaultValue - const isSpeciaColumn = ACCOUNTING_COLUMNS.includes(columnName) || ACCOUNTING_COLUMNS.includes(fieldItem.elementName) + const isSQL = String(defaultValue).includes('@SQL=') && isGetServer - if (String(defaultValue).includes('@') || isSpeciaColumn) { - parsedDefaultValue = getDefaultValue({ - ...fieldItem, - parentUuid, - isSOTrxMenu - }) - if (String(defaultValue).includes('@SQL=') && isGetServer) { - isSQL = true - } - } + const parsedDefaultValue = getDefaultValue({ + ...fieldItem, + parentUuid, + isSOTrxMenu + }) attributesObject[columnName] = parsedDefaultValue if (fieldItem.isRange && fieldItem.componentPath !== 'FieldNumber') { const { columnNameTo, elementNameTo, defaultValueTo } = fieldItem - let parsedDefaultValueTo = fieldItem.parsedDefaultValueTo - let isSQLTo = false - if (String(defaultValueTo).includes('@') || isSpeciaColumn) { - if (String(defaultValueTo).includes('@SQL=') && isGetServer) { - isSQLTo = true - } + const isSQLTo = String(defaultValueTo).includes('@SQL=') && isGetServer - parsedDefaultValueTo = getDefaultValue({ - ...fieldItem, - parentUuid, - isSOTrxMenu, - columnName: columnNameTo, - elementName: elementNameTo - }) - } + const parsedDefaultValueTo = getDefaultValue({ + ...fieldItem, + parentUuid, + isSOTrxMenu, + columnName: columnNameTo, + elementName: elementNameTo + }) attributesObject[columnNameTo] = parsedDefaultValueTo attributesRangue.push({ diff --git a/src/utils/ADempiere/contextUtils.js b/src/utils/ADempiere/contextUtils.js index bc9de27fa43..75c3aa46ea0 100644 --- a/src/utils/ADempiere/contextUtils.js +++ b/src/utils/ADempiere/contextUtils.js @@ -26,7 +26,14 @@ import evaluator from '@/utils/ADempiere/evaluator' export default evaluator -// get context state from vuex store +/** + * Get context state from vuex store + * @param {string} parentUuid UUID Window + * @param {string} containerUuid UUID Tab, Process, SmartBrowser, Report and Form + * @param {boolean} isBooleanToString if convert true to 'Y' + * @param {string} columnName (context) Entity to search + * @returns + */ export const getContext = ({ parentUuid, containerUuid, @@ -37,14 +44,16 @@ export const getContext = ({ const isPreferenceValue = columnName.startsWith('$') || columnName.startsWith('#') || columnName.startsWith(`P|`) + + // get value to session context if (isPreferenceValue) { value = store.getters.getPreference({ parentUuid, containerUuid, columnName }) - } - if (!isPreferenceValue && isEmptyValue(value)) { + } else { + // get value to container view value = store.getters.getValueOfField({ parentUuid, containerUuid, @@ -88,8 +97,8 @@ export function getPreference({ // View Preferences if (parentUuid) { value = getContext({ - parentUuid: 'P' + parentUuid, - containerUuid, + parentUuid: 'P|' + parentUuid, + containerUuid: 'P|' + containerUuid, columnName }) if (!isEmptyValue(value)) { diff --git a/src/utils/ADempiere/dictionaryUtils.js b/src/utils/ADempiere/dictionaryUtils.js index 098fd9ead7b..18d791384f6 100644 --- a/src/utils/ADempiere/dictionaryUtils.js +++ b/src/utils/ADempiere/dictionaryUtils.js @@ -15,11 +15,12 @@ // along with this program. If not, see . import evaluator from '@/utils/ADempiere/evaluator' -import { isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils' +import { arrayMatches, isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils' import { getContext, getParentFields, getPreference, parseContext } from '@/utils/ADempiere/contextUtils' import REFERENCES, { BUTTON, YES_NO, DEFAULT_SIZE, isHiddenField } from '@/utils/ADempiere/references' import { FIELD_OPERATORS_LIST } from '@/utils/ADempiere/dataUtils' import { + ACCOUNTING_COLUMNS, isDocumentStatus, READ_ONLY_FORM_COLUMNS, readOnlyColumn @@ -307,7 +308,10 @@ export function getDefaultValue({ }) { let parsedDefaultValue = defaultValue - if (String(parsedDefaultValue).includes('@') && + const isContextValue = String(parsedDefaultValue).includes('@') + const isSpeciaColumn = !isEmptyValue(arrayMatches(ACCOUNTING_COLUMNS, [columnName, elementName])) + // search value with context + if ((isSpeciaColumn || isContextValue) && String(parsedDefaultValue).trim() !== '-1') { parsedDefaultValue = parseContext({ parentUuid, @@ -318,6 +322,7 @@ export function getDefaultValue({ }).value } + // search value preference with column name if (isEmptyValue(parsedDefaultValue) && !isKey && String(parsedDefaultValue).trim() !== '-1') { parsedDefaultValue = getPreference({ @@ -326,7 +331,7 @@ export function getDefaultValue({ columnName }) - // search value preference with elementName + // search value preference with element name if (!isEmptyValue(elementName) && isEmptyValue(parsedDefaultValue)) { parsedDefaultValue = getPreference({ @@ -337,6 +342,7 @@ export function getDefaultValue({ } } + // search value with form read only if (isColumnReadOnlyForm && isEmptyValue(parsedDefaultValue)) { const { defaultValue: defaultValueColumn } = READ_ONLY_FORM_COLUMNS.find(columnItem => { return columnItem.columnName === columnName @@ -344,6 +350,12 @@ export function getDefaultValue({ parsedDefaultValue = defaultValueColumn } + // set default value + if (isEmptyValue(parsedDefaultValue) && !isContextValue) { + parsedDefaultValue = defaultValue + } + + // convert to element-ui compatible value parsedDefaultValue = parsedValueComponent({ columnName, componentPath, diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index a8055e63f34..70510d2f5c5 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -424,6 +424,27 @@ export function parsedValueComponent({ return returnValue } +/** + * Returns matching elements of arrays + * @param {array} arrayA + * @param {array} arrayB + * @returns {array} + */ +export function arrayMatches(arrayA = [], arrayB = []) { + const matches = [] + + if (isEmptyValue(arrayA) || isEmptyValue(arrayB)) { + return matches + } + arrayA.forEach(elementA => { + if (arrayB.includes(elementA)) { + matches.push(elementA) + } + }) + + return matches +} + /** * Payment method icon element-ui supported * @author Elsio Sanchez From ef9f4f56f7d9adf858d8ec444081aa2191728a3d Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Sun, 30 Jan 2022 00:48:49 -0400 Subject: [PATCH 2/2] fix logic with default value. --- .../modules/ADempiere/dictionary/window/actions.js | 13 +++++++++++++ .../modules/ADempiere/dictionary/window/getters.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/store/modules/ADempiere/dictionary/window/actions.js b/src/store/modules/ADempiere/dictionary/window/actions.js index 0da73bef85c..e466264a44b 100644 --- a/src/store/modules/ADempiere/dictionary/window/actions.js +++ b/src/store/modules/ADempiere/dictionary/window/actions.js @@ -179,6 +179,19 @@ export default { }, { root: true }) + + if (!attribute.columnName.includes('DisplayColumn')) { + const field = rootGetters.getStoredFieldFromTab({ + windowUuid: parentUuid, + tabUuid: containerUuid, + columnName: attribute.columnName + }) + // activate logics + dispatch('changeDependentFieldsList', { + field, + fieldsList: tab.fieldsList + }) + } }) dispatch('updateValuesOfContainer', { diff --git a/src/store/modules/ADempiere/dictionary/window/getters.js b/src/store/modules/ADempiere/dictionary/window/getters.js index b9c77538fb4..28e8b7d6c58 100644 --- a/src/store/modules/ADempiere/dictionary/window/getters.js +++ b/src/store/modules/ADempiere/dictionary/window/getters.js @@ -70,7 +70,7 @@ export default { getStoredFieldFromTab: (state, getters) => ({ windowUuid, tabUuid, columnName, fieldUuid }) => { return getters.getStoredFieldsFromTab(windowUuid, tabUuid) - .map(field => { + .find(field => { return field.columnName === columnName || field.uuid === fieldUuid }) },