From 02c634e56dbced96d041dcbfaa20d415677188aa Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Tue, 25 Feb 2020 08:49:20 -0400 Subject: [PATCH] fix: Fields that are not displayed by default and have a default value. (#345) --- .../ADempiere/Field/FieldSelect.vue | 3 + src/router/modules/ADempiere/menu.js | 55 +++++++++++-------- src/store/modules/ADempiere/browser.js | 12 +++- src/store/modules/ADempiere/window.js | 9 ++- src/utils/ADempiere/contextUtils.js | 13 +++-- src/utils/ADempiere/dictionaryUtils.js | 41 +++++++++++--- src/utils/ADempiere/valueUtils.js | 3 + 7 files changed, 97 insertions(+), 39 deletions(-) diff --git a/src/components/ADempiere/Field/FieldSelect.vue b/src/components/ADempiere/Field/FieldSelect.vue index 24b9bdab..e680562d 100644 --- a/src/components/ADempiere/Field/FieldSelect.vue +++ b/src/components/ADempiere/Field/FieldSelect.vue @@ -136,6 +136,9 @@ export default { }, 'metadata.value'(value) { if (!this.metadata.inTable) { + if (typeof value === 'boolean') { + value = value ? 'Y' : 'N' + } if (this.metadata.displayed) { if (!this.options.some(option => option.key === value)) { this.options.push({ diff --git a/src/router/modules/ADempiere/menu.js b/src/router/modules/ADempiere/menu.js index ed682717..db6beaf7 100644 --- a/src/router/modules/ADempiere/menu.js +++ b/src/router/modules/ADempiere/menu.js @@ -59,10 +59,10 @@ export function loadMainMenu() { return new Promise(resolve => { getMenu(getToken()).then(menuResponse => { const asyncRoutesMap = [] - menuResponse.childsList.forEach(menu => { - const optionMenu = getRouteFromMenuItem(menu) - if (menu.isSummary) { - menu.childsList.forEach(menu => { + menuResponse.childsList.forEach(menuElement => { + const optionMenu = getRouteFromMenuItem(menuElement) + if (menuElement.isSummary) { + menuElement.childsList.forEach(menu => { const childsSumaryConverted = getChildFromAction(menu, 0) optionMenu.children.push(childsSumaryConverted) @@ -70,7 +70,7 @@ export function loadMainMenu() { optionMenu.meta.childs.push(childsSumaryConverted) }) } else { - const childsConverted = getChildFromAction(menu) + const childsConverted = getChildFromAction(menuElement) optionMenu.children.push(childsConverted) optionMenu.meta.childs.push(childsConverted) @@ -99,16 +99,20 @@ function getChildFromAction(menu, index) { name: menu.uuid, hidden: index > 0, meta: { - isIndex: actionAttributes.isIndex, - title: menu.name, - description: menu.description, - uuid: menu.referenceUuid, - tabUuid: '', - type: actionAttributes.name, - parentUuid: menu.parentUuid, - icon: actionAttributes.icon, alwaysShow: true, + description: menu.description, + icon: actionAttributes.icon, + isIndex: actionAttributes.isIndex, + isReadOnly: menu.isReadOnly, + isSummary: menu.isSummary, + isSOTrx: menu.isSOTrx, + parentUuid: menu.parentUuid, noCache: false, + referenceUuid: menu.referenceUuid, + tabUuid: '', + title: menu.name, + type: actionAttributes.name, + uuid: menu.referenceUuid, childs: [] } } @@ -134,11 +138,15 @@ function getRouteFromMenuItem(menu) { component: Layout, name: menu.uuid, meta: { - title: menu.name, description: menu.description, - type: actionAttributes.name, icon: actionAttributes.icon, + isReadOnly: menu.isReadOnly, + isSummary: menu.isSummary, + isSOTrx: menu.isSOTrx, noCache: true, + referenceUuid: menu.referenceUuid, + title: menu.name, + type: actionAttributes.name, childs: [] }, children: [{ @@ -147,14 +155,17 @@ function getRouteFromMenuItem(menu) { name: menu.uuid + '-index', hidden: true, meta: { - isIndex: actionAttributes.isIndex, - parentUuid: menu.uuid, - title: menu.name, - description: menu.description, - type: actionAttributes.name, - icon: actionAttributes.icon, - noCache: true, breadcrumb: false, + description: menu.description, + icon: actionAttributes.icon, + isIndex: actionAttributes.isIndex, + isReadOnly: menu.isReadOnly, + isSOTrx: menu.isSOTrx, + noCache: true, + parentUuid: menu.uuid, + referenceUuid: menu.referenceUuid, + title: menu.name, + type: actionAttributes.name, childs: [] } }] diff --git a/src/store/modules/ADempiere/browser.js b/src/store/modules/ADempiere/browser.js index b3da8d9e..a82760b4 100644 --- a/src/store/modules/ADempiere/browser.js +++ b/src/store/modules/ADempiere/browser.js @@ -47,10 +47,18 @@ const browser = { ...additionalAttributes, fieldListIndex: index } - const field = generateField(fieldItem, someAttributes) + const field = generateField({ + fieldToGenerate: fieldItem, + moreAttributes: someAttributes, + isSOTrxMenu: routeToDelete.meta.isSOTrx + }) // Add new field if is range number if (field.isRange && field.componentPath === 'FieldNumber') { - const fieldRange = generateField(fieldItem, someAttributes, true) + const fieldRange = generateField({ + fieldToGenerate: fieldItem, + moreAttributes: someAttributes, + typeRange: true + }) if (!isEmptyValue(fieldRange.value)) { fieldRange.isShowedFromUser = true } diff --git a/src/store/modules/ADempiere/window.js b/src/store/modules/ADempiere/window.js index 832ffce9..d5e38d78 100644 --- a/src/store/modules/ADempiere/window.js +++ b/src/store/modules/ADempiere/window.js @@ -256,9 +256,12 @@ const window = { let fieldLinkColumnName // Convert from gRPC const fieldsList = tabResponse.fieldsList.map((fieldItem, index) => { - fieldItem = generateField(fieldItem, { - ...additionalAttributes, - fieldListIndex: index + fieldItem = generateField({ + fieldToGenerate: fieldItem, + moreAttributes: { + ...additionalAttributes, + fieldListIndex: index + } }) if (fieldItem.sequence > fieldUuidsequence) { fieldUuidsequence = fieldItem.sequence diff --git a/src/utils/ADempiere/contextUtils.js b/src/utils/ADempiere/contextUtils.js index 4c2ee366..49e90a5f 100644 --- a/src/utils/ADempiere/contextUtils.js +++ b/src/utils/ADempiere/contextUtils.js @@ -71,7 +71,8 @@ export function parseContext({ columnName, value, isSQL = false, - isBooleanToString = false + isBooleanToString = false, + isSOTrxMenu }) { let isError = false const errorsList = [] @@ -129,18 +130,22 @@ export function parseContext({ } } - if ((contextInfo === undefined || contextInfo.length === 0) && + if (isEmptyValue(contextInfo) && (token.startsWith('#') || token.startsWith('$'))) { contextInfo = getContext({ columnName }) // get global context } + // menu attribute isEmptyValue isSOTrx + if (!isEmptyValue(isSOTrxMenu) && token === 'IsSOTrx' && isEmptyValue(contextInfo)) { + contextInfo = isSOTrxMenu + } if (contextInfo === undefined || contextInfo.length === 0) { console.info(`No Context for: ${token}`) isError = true errorsList.push(token) } else { - if (typeof contextInfo === 'object') { + if (['object', 'boolean'].includes(typeof contextInfo)) { outString = contextInfo } else { outString = outString + contextInfo // replace context with Context @@ -150,7 +155,7 @@ export function parseContext({ inString = inString.substring(secondIndexTag + 1, inString.length) // from second @ firstIndexTag = inString.indexOf('@') } - if (typeof contextInfo !== 'object') { + if (!['object', 'boolean'].includes(typeof contextInfo)) { outString = outString + inString // add the rest of the string } if (isSQL) { diff --git a/src/utils/ADempiere/dictionaryUtils.js b/src/utils/ADempiere/dictionaryUtils.js index 0f26cbd0..b63c8dc0 100644 --- a/src/utils/ADempiere/dictionaryUtils.js +++ b/src/utils/ADempiere/dictionaryUtils.js @@ -11,7 +11,12 @@ import language from '@/lang' * @param {object} moreAttributes, additional attributes * @param {boolean} typeRange, indicate if this field is a range used as _To */ -export function generateField(fieldToGenerate, moreAttributes, typeRange = false) { +export function generateField({ + fieldToGenerate, + moreAttributes, + typeRange = false, + isSOTrxMenu +}) { let isShowedFromUser = false // verify if it no overwrite value with ...moreAttributes if (moreAttributes.isShowedFromUser) { @@ -27,10 +32,14 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false parsedDefaultValue = parseContext({ ...moreAttributes, columnName: fieldToGenerate.columnName, - value: parsedDefaultValue + value: parsedDefaultValue, + isSOTrxMenu: isSOTrxMenu }).value } - if (isEmptyValue(parsedDefaultValue) && String(parsedDefaultValue).trim() !== '-1') { + + if ((isEmptyValue(parsedDefaultValue) || + String(parsedDefaultValue).includes('@')) && + String(parsedDefaultValue).trim() !== '-1') { parsedDefaultValue = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, @@ -38,7 +47,10 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false }) // search value preference with elementName - if (isEmptyValue(parsedDefaultValue) && !isEmptyValue(fieldToGenerate.elementName)) { + if (!isEmptyValue(fieldToGenerate.elementName) && + (isEmptyValue(parsedDefaultValue) || + String(parsedDefaultValue).includes('@')) && + String(parsedDefaultValue).trim() !== '-1') { parsedDefaultValue = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, @@ -65,7 +77,10 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false value: parsedDefaultValueTo }).value } - if (isEmptyValue(parsedDefaultValueTo) && String(parsedDefaultValueTo).trim() !== '-1') { + + if ((isEmptyValue(parsedDefaultValueTo) || + String(parsedDefaultValueTo).includes('@')) && + String(parsedDefaultValueTo).trim() !== '-1') { parsedDefaultValueTo = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, @@ -73,7 +88,10 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false }) // search value preference with elementName - if (isEmptyValue(parsedDefaultValueTo) && !isEmptyValue(fieldToGenerate.elementName)) { + if (!isEmptyValue(fieldToGenerate.elementName) && + (isEmptyValue(parsedDefaultValueTo) || + String(parsedDefaultValueTo).includes('@')) && + String(parsedDefaultValueTo).trim() !== '-1') { parsedDefaultValueTo = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, @@ -211,10 +229,17 @@ export function generateProcess({ processToGenerate, containerUuidAssociated = u fieldDefinitionList = processToGenerate.parametersList .map(fieldItem => { - const field = generateField(fieldItem, additionalAttributes) + const field = generateField({ + fieldToGenerate: fieldItem, + moreAttributes: additionalAttributes + }) // Add new field if is range number if (field.isRange && field.componentPath === 'FieldNumber') { - const fieldRange = generateField(fieldItem, additionalAttributes, true) + const fieldRange = generateField({ + fieldToGenerate: fieldItem, + moreAttributes: additionalAttributes, + typeRange: true + }) if (!isEmptyValue(fieldRange.value)) { fieldRange.isShowedFromUser = true } diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index b9275151..59815a6b 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -350,6 +350,9 @@ export function parsedValueComponent({ fieldType, value, referenceType, isMandat if (String(value).trim() === '') { value = undefined } + if (typeof value === 'boolean') { + value = value ? 'Y' : 'N' + } if (referenceType === 'TableDirect') { if (value !== '' && value !== null && value !== undefined) { value = Number(value)