Skip to content

Commit

Permalink
fix: PanJiaChen#2294 Set context on Create From Order smart browse.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Jul 15, 2024
1 parent fd2cafc commit 8063327
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 190 deletions.
4 changes: 3 additions & 1 deletion src/components/ADempiere/FieldDefinition/FieldButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ import { RECORD_ID } from '@/utils/ADempiere/constants/systemColumns'
import {
runProcessOfWindow,
generateReportOfWindow,
openBrowserAssociated,
openDocumentAction,
openFormAssociated
} from '@/utils/ADempiere/dictionary/window'
import {
openBrowserAssociated
} from '@/utils/ADempiere/dictionary/window/actionsMenu'
import { isEmptyValue, isSameValues } from '@/utils/ADempiere/valueUtils'
import { getContextAttributes, generateContextKey } from '@/utils/ADempiere/contextUtils/contextAttributes'
import {
Expand Down
42 changes: 6 additions & 36 deletions src/store/modules/ADempiere/dictionary/browser/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import { DISPLAY_COLUMN_PREFIX } from '@/utils/ADempiere/dictionaryUtils'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { isSalesTransaction } from '@/utils/ADempiere/contextUtils'
import { generatePanelAndFields } from '@/utils/ADempiere/dictionary/panel.js'
import { copyWindowContextOnBrowser } from '@/utils/ADempiere/contextUtils/contextBrowser'
import {
containerManager,
isDisplayedField, isMandatoryField,
evaluateDefaultFieldShowed,
evaluateDefaultColumnShowed
Expand Down Expand Up @@ -122,41 +122,11 @@ export default {

// set parent context
if (!isEmptyValue(parentUuid) || !isEmptyValue(containerUuid)) {
const parentContext = rootGetters.getValuesView({
parentUuid,
containerUuid,
format: 'object'
})
dispatch('updateValuesOfContainer', {
containerUuid: browserUuid,
attributes: parentContext
})

browserDefinition.fieldsList.forEach(itemField => {
const { isSameColumnElement, column_name, element_name } = itemField
if (!isSameColumnElement) {
// const currentContextValue = parentContext.find(itemAttribute => {
// return itemAttribute.columnName === itemField.element_name
// })
const currentContextValue = parentContext[element_name]
if (!isEmptyValue(currentContextValue)) {
commit('updateValueOfField', {
containerUuid: browserUuid,
columnName: element_name,
value: currentContextValue
})
commit('updateValueOfField', {
containerUuid: browserUuid,
columnName: column_name,
value: currentContextValue
})
}
// change Dependents
dispatch('changeDependentFieldsList', {
field: itemField,
containerManager
})
}
copyWindowContextOnBrowser({
browserUuid,
fieldsList: browserDefinition.fieldsList,
windowUuid: parentUuid,
tabUuid: containerUuid
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/ADempiere/dictionary/window/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
exportCurrentRecord,
runProcessOfWindow,
generateReportOfWindow,
openBrowserAssociated,
openDocumentAction,
openFormAssociated,
refreshRecord,
Expand All @@ -50,6 +49,7 @@ import {
undoChange
} from '@/utils/ADempiere/dictionary/window'
import {
openBrowserAssociated,
openSequenceTab
} from '@/utils/ADempiere/dictionary/window/actionsMenu'
import {
Expand Down
153 changes: 153 additions & 0 deletions src/utils/ADempiere/contextUtils/contextBrowser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/**
* ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
* Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com
* Contributor(s): Edwin Betancourt [email protected] https://github.com/EdwinBetanc0urt
* 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 <https://www.gnu.org/licenses/>.
*/

import fieldList from '@/components/ADempiere/Form/VMatch/fieldList'
import store from '@/store'

// Constants
import {
RECORD_ID,
IS_SO_TRX
} from '@/utils/ADempiere/constants/systemColumns'
import {
containerManager as CONTAINER_MANAGER_BROWSER
} from '@/utils/ADempiere/dictionary/browser'

// Utils and Helpers Methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { isSalesTransaction } from '@/utils/ADempiere/contextUtils'
import { getContextAttributes } from '@/utils/ADempiere/contextUtils/contextAttributes'

export function copyWindowContextOnBrowser({
browserUuid,
fieldsList = [],
windowUuid,
tabUuid
}) {
// set parent context
if (isEmptyValue(windowUuid) || isEmptyValue(tabUuid)) {
return
}

const storedTab = store.getters.getStoredTab(windowUuid, tabUuid)
if (isEmptyValue(storedTab)) {
return
}
const { keyColumn, table, parent_column_name, link_column_name } = storedTab
const { key_columns } = table

let relatedColumns = key_columns
// TODO: Validate element columns
const parentColumns = storedTab.fieldsList
.filter(fieldItem => {
return fieldItem.is_parent || fieldItem.is_key || fieldItem.is_mandatory
})
.map(fieldItem => {
return fieldItem.column_name
})

if (!isEmptyValue(parent_column_name)) {
relatedColumns.push(parent_column_name)
}
if (!isEmptyValue(link_column_name)) {
relatedColumns.push(link_column_name)
}
relatedColumns = relatedColumns.concat(parentColumns).sort()

// set context values
const parentValues = getContextAttributes({
parentUuid: windowUuid,
containerUuid: tabUuid,
contextColumnNames: relatedColumns
})

// Set Record ID
const recordId = store.getters.getValueOfField({
parentUuid: windowUuid,
containerUuid: tabUuid,
columnName: keyColumn
})
if (!isEmptyValue(recordId)) {
parentValues.push({
columnName: RECORD_ID,
value: recordId
})
}

// Always set Is Sales Transaction by window
const isSOTrx = isSalesTransaction({
parentUuid: windowUuid,
containerUuid: tabUuid,
isRecord: true
})
parentValues.push({
columnName: IS_SO_TRX,
value: isSOTrx
})

store.dispatch('updateValuesOfContainer', {
containerUuid: browserUuid,
attributes: parentValues
})

const tabContext = store.getters.getValuesView({
parentUuid: windowUuid,
containerUuid: tabUuid,
format: 'object'
})
store.dispatch('updateValuesOfContainer', {
containerUuid: browserUuid,
attributes: tabContext
})

if (isEmptyValue(fieldList)) {
fieldsList = store.getters.getStoredFieldsFromBrowser(browserUuid)
}

fieldsList.forEach(itemField => {
const {
isSameColumnElement, column_name, element_name, default_value, default_value_to
} = itemField

// no set value by window
if (isEmptyValue(default_value) && isEmptyValue(default_value_to)) {
return
}

if (!isSameColumnElement) {
const currentContextValue = tabContext[element_name]
if (!isEmptyValue(currentContextValue)) {
store.commit('updateValueOfField', {
containerUuid: browserUuid,
columnName: element_name,
value: currentContextValue
})
store.commit('updateValueOfField', {
containerUuid: browserUuid,
columnName: column_name,
value: currentContextValue
})
}
// change Dependents
store.dispatch('changeDependentFieldsList', {
field: itemField,
containerManager: CONTAINER_MANAGER_BROWSER
})
}
})
}
86 changes: 86 additions & 0 deletions src/utils/ADempiere/dictionary/window/actionsMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
*/

import language from '@/lang'
import router from '@/router'
import store from '@/store'

// Utils and Helper Methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { copyWindowContextOnBrowser } from '@/utils/ADempiere/contextUtils/contextBrowser'
import { zoomIn } from '@/utils/ADempiere/coreUtils'

/**
* Run process associated on table or button field
Expand Down Expand Up @@ -54,3 +57,86 @@ export const openSequenceTab = {
})
}
}

/**
* Open Smart Browser Associated in Process
*/
export const openBrowserAssociated = {
name: language.t('actionMenu.openSmartBrowser'),
enabled: ({ parentUuid, containerUuid }) => {
const recordUuid = store.getters.getUuidOfContainer(containerUuid)
return !isEmptyValue(recordUuid)
},
isSvgIcon: true,
icon: 'search',
actionName: 'openBrowserAssociated',
openBrowserAssociated: function({ parentUuid, containerUuid, uuid, browserId }) {
if (isEmptyValue(browserId) || browserId <= 0) {
const process = store.getters.getStoredProcessFromTab({
windowUuid: parentUuid,
tabUuid: containerUuid,
processUuid: uuid
})
browserId = process.browser.id
}
const browserUuid = store.getters.getStoredBrowserUuidById(browserId)
const storedBrowser = store.getters.getStoredBrowser(browserUuid)
if (!isEmptyValue(storedBrowser)) {
// overwrite values
store.dispatch('setBrowserDefaultValues', {
containerUuid: browserUuid
})

// copy context values
copyWindowContextOnBrowser({
browserUuid,
fieldsList: storedBrowser.fieldsList,
windowUuid: parentUuid,
tabUuid: containerUuid
})

// clear resutls
store.dispatch('clearBrowserData', {
containerUuid: browserUuid
})
}

// set record id from window
const storedTab = store.getters.getStoredTab(parentUuid, containerUuid)
const { keyColumn } = storedTab

// Set Record ID
const recordId = store.getters.getValueOfField({
parentUuid,
containerUuid,
columnName: keyColumn
})

const containerIdentifier = 'browser_' + browserId
const inMenu = zoomIn({
attributeValue: containerIdentifier,
attributeName: 'containerKey',
query: {
parentUuid,
containerUuid,
recordId
},
isShowMessage: false
})

if (!inMenu) {
router.push({
name: 'Smart Browser',
params: {
browserId: browserId
// browserUuid
},
query: {
parentUuid,
containerUuid,
recordId
}
}, () => {})
}
}
}
Loading

0 comments on commit 8063327

Please sign in to comment.