From 5982b7fc2e7d0335b5f6847a535e6f64ae785ba5 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Wed, 16 Oct 2024 15:23:36 -0400 Subject: [PATCH] feat: Run Process with window selection. --- .../business-data/runBusinessProcess.ts | 15 ++- src/store/modules/ADempiere/processManager.js | 36 ++++++- src/store/modules/ADempiere/windowManager.js | 100 +++++++++++++++++- .../ADempiere/dictionary/window/index.js | 50 +++++++-- 4 files changed, 183 insertions(+), 18 deletions(-) diff --git a/src/api/ADempiere/business-data/runBusinessProcess.ts b/src/api/ADempiere/business-data/runBusinessProcess.ts index 1e1b2de261..ee13a98bf6 100644 --- a/src/api/ADempiere/business-data/runBusinessProcess.ts +++ b/src/api/ADempiere/business-data/runBusinessProcess.ts @@ -19,6 +19,9 @@ // Get Instance for connection import { request } from '@/utils/ADempiere/request' +// Utils and Helper Methods +import { isEmptyValue } from '@/utils/ADempiere/valueUtils' + /** * Get default value for a field, parameter or query criteria * @param {integer} id, identifier of field @@ -72,13 +75,19 @@ export function requestRunBusinessProcessAsWindow({ id, parametersList, tableName, - recordId + recordId, + selectionsList }) { + let url = `/business-data/process/${id}/window/${tableName}` + if (isEmptyValue(selectionsList) || (!isEmptyValue(selectionsList) && selectionsList.length === 1)) { + url += `/${recordId}` + } return request({ - url: `/business-data/process/${id}/window/${tableName}/${recordId}`, + url: url, method: 'post', data: { - parameters: parametersList + parameters: parametersList, + selections: selectionsList } }) } diff --git a/src/store/modules/ADempiere/processManager.js b/src/store/modules/ADempiere/processManager.js index ba598b38a9..ccb694a7f9 100644 --- a/src/store/modules/ADempiere/processManager.js +++ b/src/store/modules/ADempiere/processManager.js @@ -354,7 +354,10 @@ const processManager = { const processModal = getters.getModalDialogManager({ containerUuid: containerUuid }) - const currentProcess = storedTab.processes.find(process => process.name === processModal.title) + const storedProcessDefinition = storedTab.processes.find(process => { + // return process.name === processModal.title + return process.uuid === processModal.containerUuid + }) if (isEmptyValue(parametersList)) { const fieldsList = getters.getStoredFieldsFromProcess(containerUuid) parametersList = rootGetters.getProcessParameters({ @@ -363,6 +366,28 @@ const processManager = { }) } + let selectionsList = [] + if (storedProcessDefinition.is_multi_selection) { + let recordsSelection = [] + if (storedTab.isShowedTableRecords) { + recordsSelection = getters.getTabSelectionsList({ + containerUuid + }) + } else { + const currentRow = getters.getTabCurrentRow({ + containerUuid: storedTab.uuid + }) + recordsSelection = [ + currentRow + ] + } + selectionsList = rootGetters.getTabSelectionToServer({ + parentUuid: windowsUuid, + containerUuid: storedTab.uuid, + selectionsList: recordsSelection + }) + } + const isSession = !isEmptyValue(getToken()) let procesingNotification = { close: () => false @@ -370,8 +395,8 @@ const processManager = { if (isSession) { procesingNotification = showNotification({ title: lang.t('notifications.processing'), - message: currentProcess.name, - summary: currentProcess.description, + message: storedProcessDefinition.name, + summary: storedProcessDefinition.description, type: 'info' }) } @@ -387,8 +412,9 @@ const processManager = { } requestRunBusinessProcessAsWindow({ - id: currentProcess.internal_id, + id: storedProcessDefinition.internal_id, parametersList, + selectionsList, tableName, recordId: recordId }) @@ -413,7 +439,7 @@ const processManager = { dispatch('finishProcess', { summary, - name: currentProcess.name, + name: storedProcessDefinition.name, isError: isProcessedError }) .then(() => { diff --git a/src/store/modules/ADempiere/windowManager.js b/src/store/modules/ADempiere/windowManager.js index bfca4d977d..adadce816b 100644 --- a/src/store/modules/ADempiere/windowManager.js +++ b/src/store/modules/ADempiere/windowManager.js @@ -30,10 +30,13 @@ import { // Constants import { UUID } from '@/utils/ADempiere/constants/systemColumns' -import { ROW_ATTRIBUTES } from '@/utils/ADempiere/tableUtils' -import { IS_ADVANCED_QUERY } from '@/utils/ADempiere/dictionaryUtils' +import { ROW_ATTRIBUTES, ROW_KEY_ATTRIBUTES } from '@/utils/ADempiere/tableUtils' import { - IGNORE_VALUE_OPERATORS_LIST, MULTIPLE_VALUES_OPERATORS_LIST, RANGE_VALUE_OPERATORS_LIST + DISPLAY_COLUMN_PREFIX, IDENTIFIER_COLUMN_SUFFIX, IS_ADVANCED_QUERY +} from '@/utils/ADempiere/dictionaryUtils' +import { + IGNORE_VALUE_OPERATORS_LIST, MULTIPLE_VALUES_OPERATORS_LIST, + RANGE_VALUE_OPERATORS_LIST } from '@/utils/ADempiere/dataUtils' import { FIELDS_DATE } from '@/utils/ADempiere/references' @@ -41,10 +44,11 @@ import { FIELDS_DATE } from '@/utils/ADempiere/references' import { containerManager } from '@/utils/ADempiere/dictionary/window' import { isSalesTransaction } from '@/utils/ADempiere/contextUtils' import { getContextAttributes, generateContextKey } from '@/utils/ADempiere/contextUtils/contextAttributes' -import { isEmptyValue, setRecordPath } from '@/utils/ADempiere/valueUtils.js' +import { getTypeOfValue, isEmptyValue, setRecordPath } from '@/utils/ADempiere/valueUtils.js' import { convertObjectToKeyValue } from '@/utils/ADempiere/valueFormat' import { showMessage } from '@/utils/ADempiere/notification' import { generatePageToken } from '@/utils/ADempiere/dataUtils' +import { isDateField, isDecimalField } from '@/utils/ADempiere/references' const initState = { tabData: {}, @@ -1006,6 +1010,94 @@ const windowManager = { getTabSelectionsList: (state, getters) => ({ containerUuid }) => { return getters.getTabData({ containerUuid }).selectionsList }, + + /** + * Getter converter selection data record in format + * @param {string} containerUuid + * @param {array} selection + * [{ + * selectionId: keyColumn Value, + * values: [{ columnName, value }] + * }] + */ + getTabSelectionToServer: (state, getters, rootState, rootGetters) => ({ + parentUuid, + containerUuid, + selectionsList = [] + }) => { + const selectionToServer = [] + + if (isEmptyValue(selectionsList)) { + selectionsList = getters.getTabSelectionsList({ + containerUuid + }) + } + + if (isEmptyValue(selectionsList)) { + return selectionToServer + } + + const { fieldsList, table_name, table } = rootGetters.getStoredTab( + parentUuid, + containerUuid + ) + let keyColumn = table_name + IDENTIFIER_COLUMN_SUFFIX + if (!isEmptyValue(table.key_columns) && table.key_columns.length === 1) { + keyColumn = table.key_columns.at(0) + } + + // reduce list + const fieldsListSelection = fieldsList + .filter(itemField => { + return itemField.is_key || itemField.is_identifier + }) + .map(itemField => { + return { + columnName: itemField.column_name, + display_type: itemField.display_type + } + }) + + selectionsList.forEach(itemRow => { + const attributesList = {} + + Object.keys(itemRow).forEach(columnName => { + if (!columnName.startsWith(DISPLAY_COLUMN_PREFIX) && !ROW_KEY_ATTRIBUTES.includes(columnName)) { + const currentField = fieldsListSelection.find(itemField => { + return itemField.columnName === columnName + }) + // evaluate metadata attributes before to convert + if (!isEmptyValue(currentField)) { + const value = itemRow[columnName] + let serverValue = value + // types `decimal` and `date` is a object struct + if (getTypeOfValue(value) !== 'OBJECT' || isEmptyValue(value.type)) { + if (isDateField(currentField.display_type)) { + serverValue = { + type: 'date', + value: value + } + } else if (isDecimalField(currentField.display_type)) { + serverValue = { + type: 'decimal', + value: value + } + } + } + attributesList[columnName] = serverValue + } + } + }) + + selectionToServer.push({ + selectionId: itemRow[keyColumn], + values: attributesList + }) + }) + + return selectionToServer + }, + getTabPageNumber: (state, getters) => ({ containerUuid }) => { return getters.getTabData({ containerUuid }).pageNumber }, diff --git a/src/utils/ADempiere/dictionary/window/index.js b/src/utils/ADempiere/dictionary/window/index.js index d6662105ed..d8d5c397a4 100644 --- a/src/utils/ADempiere/dictionary/window/index.js +++ b/src/utils/ADempiere/dictionary/window/index.js @@ -863,9 +863,28 @@ export const exportCurrentRecord = { */ export const runProcessOfWindow = { name: language.t('actionMenu.runProcess'), - enabled: ({ parentUuid, containerUuid }) => { - const recordUuid = store.getters.getUuidOfContainer(containerUuid) - return !isEmptyValue(recordUuid) + enabled: ({ parentUuid, containerUuid, uuid }) => { + const storedTab = store.getters.getStoredTab( + parentUuid, + containerUuid + ) + if (!storedTab.isShowedTableRecords) { + const recordUuid = store.getters.getUuidOfContainer(containerUuid) + return !isEmptyValue(recordUuid) + } + + // multi selection process + const recordsSelection = store.getters.getTabSelectionsList({ + containerUuid + }) + if (isEmptyValue(recordsSelection)) { + return false + } + const currentProcess = storedTab.processes.find(process => { + // return process.name === processModal.title + return process.uuid === uuid + }) + return currentProcess.is_multi_selection }, svg: false, icon: 'el-icon-setting', @@ -886,9 +905,28 @@ export const runProcessOfWindow = { */ export const generateReportOfWindow = { name: language.t('actionMenu.generateReport'), - enabled: ({ parentUuid, containerUuid }) => { - const recordUuid = store.getters.getUuidOfContainer(containerUuid) - return !isEmptyValue(recordUuid) + enabled: ({ parentUuid, containerUuid, uuid }) => { + const storedTab = store.getters.getStoredTab( + parentUuid, + containerUuid + ) + if (!storedTab.isShowedTableRecords) { + const recordUuid = store.getters.getUuidOfContainer(containerUuid) + return !isEmptyValue(recordUuid) + } + + // multi selection process + const recordsSelection = store.getters.getTabSelectionsList({ + containerUuid + }) + if (isEmptyValue(recordsSelection)) { + return false + } + const currentProcess = storedTab.processes.find(process => { + // return process.name === processModal.title + return process.uuid === uuid + }) + return currentProcess.is_multi_selection }, isSvgIcon: true, icon: 'skill',