From d55e7b7d4d8f766c9a7d2436f7a76fd821b6b99d Mon Sep 17 00:00:00 2001 From: Leonel Matos Date: Tue, 11 Feb 2020 15:51:57 -0400 Subject: [PATCH] Bugfix create order lines (#311) * Bugfix create order lines * bugfix context boolean value * validate void label for create entity * rename variables --- src/store/modules/ADempiere/data.js | 14 +++++-- src/store/modules/ADempiere/panel.js | 4 +- src/utils/ADempiere/contextUtils.js | 61 +++++++++++++++------------- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/store/modules/ADempiere/data.js b/src/store/modules/ADempiere/data.js index 46312d01..3e7b5f59 100644 --- a/src/store/modules/ADempiere/data.js +++ b/src/store/modules/ADempiere/data.js @@ -195,6 +195,9 @@ const data = { // overwrite value with column link if (!isEmptyValue(linkColumnName) && linkColumnName === itemField.columnName) { valueGetDisplayColumn = valueLink + if (isEmptyValue(values[itemField.columnName])) { + values[itemField.columnName] = valueGetDisplayColumn + } } // break this itineration if is empty @@ -209,7 +212,7 @@ const data = { valueGetDisplayColumn = parseInt(valueGetDisplayColumn, 10) } } - if (!isEmptyValue(valueGetDisplayColumn) && String(valueGetDisplayColumn) === '[object Object]') { + if (!isEmptyValue(valueGetDisplayColumn) && String(valueGetDisplayColumn) === '[object Object]' && valueGetDisplayColumn.isSQL) { // get value from direct Query dispatch('getRecordBySQL', { query: valueGetDisplayColumn.query, @@ -226,7 +229,7 @@ const data = { containerUuid, isNew, isEdit, - values + row: values }) } }) @@ -246,6 +249,9 @@ const data = { // if there is a lookup option, assign the display column with the label if (option) { values[`DisplayColumn_${itemField.columnName}`] = option.label + if (isEmptyValue(option.label) && !itemField.isMandatory) { + values[itemField.columnName] = undefined + } return } if (linkColumnName === itemField.columnName) { @@ -629,8 +635,8 @@ const data = { notifyRowTableChange({ commit, getters, rootGetters }, objectParams) { const { parentUuid, containerUuid, isEdit = true } = objectParams var currentValues = {} - if (objectParams.hasOwnProperty('values')) { - currentValues = objectParams.values + if (objectParams.hasOwnProperty('row')) { + currentValues = objectParams.row } else { currentValues = rootGetters.getColumnNamesAndValues({ parentUuid, diff --git a/src/store/modules/ADempiere/panel.js b/src/store/modules/ADempiere/panel.js index 89ff7d28..757f5369 100644 --- a/src/store/modules/ADempiere/panel.js +++ b/src/store/modules/ADempiere/panel.js @@ -1073,14 +1073,14 @@ const panel = { columnName: fieldItem.columnName, value: fieldItem.defaultValue, isSQL - }).value + }) } valueToReturn = parsedValueComponent({ fieldType: fieldItem.componentPath, referenceType: fieldItem.referenceType, isMandatory: fieldItem.isMandatory, - value: valueToReturn + value: String(valueToReturn) === '[object Object]' && valueToReturn.isSQL ? valueToReturn : String(valueToReturn) === '[object Object]' ? valueToReturn.value : valueToReturn }) attributesObject[fieldItem.columnName] = valueToReturn diff --git a/src/utils/ADempiere/contextUtils.js b/src/utils/ADempiere/contextUtils.js index 78acebd6..4c2ee366 100644 --- a/src/utils/ADempiere/contextUtils.js +++ b/src/utils/ADempiere/contextUtils.js @@ -73,7 +73,6 @@ export function parseContext({ isSQL = false, isBooleanToString = false }) { - // const isBooleanToString = value.includes('@SQL=') let isError = false const errorsList = [] value = String(value) @@ -94,74 +93,78 @@ export function parseContext({ // } var token - var inStr = value - var outStr = '' + var inString = value + var outString = '' - let firstIndexTag = inStr.indexOf('@') + let firstIndexTag = inString.indexOf('@') while (firstIndexTag !== -1) { - outStr = outStr + inStr.substring(0, firstIndexTag) // up to @ - inStr = inStr.substring(firstIndexTag + 1, inStr.length) // from first @ - const secondIndexTag = inStr.indexOf('@') // next @ + outString = outString + inString.substring(0, firstIndexTag) // up to @ + inString = inString.substring(firstIndexTag + 1, inString.length) // from first @ + const secondIndexTag = inString.indexOf('@') // next @ // no exists second tag if (secondIndexTag < 0) { - console.info(`No second tag: ${inStr}`) + console.info(`No second tag: ${inString}`) return { value: undefined, isError: true, - errorsList + errorsList, + isSQL } } - token = inStr.substring(0, secondIndexTag) + token = inString.substring(0, secondIndexTag) columnName = token - var ctxInfo = getContext({ + var contextInfo = getContext({ parentUuid, containerUuid, columnName }) // get context - if (isBooleanToString && typeof ctxInfo === 'boolean') { - ctxInfo = 'N' - if (ctxInfo) { - ctxInfo = 'Y' + if (isBooleanToString && typeof contextInfo === 'boolean') { + if (contextInfo) { + contextInfo = 'Y' + } else { + contextInfo = 'N' } } - if ((ctxInfo === undefined || ctxInfo.length === 0) && + if ((contextInfo === undefined || contextInfo.length === 0) && (token.startsWith('#') || token.startsWith('$'))) { - ctxInfo = getContext({ + contextInfo = getContext({ columnName }) // get global context } - if (ctxInfo === undefined || ctxInfo.length === 0) { + if (contextInfo === undefined || contextInfo.length === 0) { console.info(`No Context for: ${token}`) isError = true errorsList.push(token) } else { - if (typeof ctxInfo === 'object') { - outStr = ctxInfo + if (typeof contextInfo === 'object') { + outString = contextInfo } else { - outStr = outStr + ctxInfo // replace context with Context + outString = outString + contextInfo // replace context with Context } } - inStr = inStr.substring(secondIndexTag + 1, inStr.length) // from second @ - firstIndexTag = inStr.indexOf('@') + inString = inString.substring(secondIndexTag + 1, inString.length) // from second @ + firstIndexTag = inString.indexOf('@') } - if (typeof ctxInfo !== 'object') { - outStr = outStr + inStr // add the rest of the string + if (typeof contextInfo !== 'object') { + outString = outString + inString // add the rest of the string } if (isSQL) { return { - query: outStr, - value: ctxInfo + query: outString, + value: contextInfo, + isSQL } } return { - value: outStr, + value: outString, isError, - errorsList + errorsList, + isSQL } } // parseContext