Skip to content

Commit

Permalink
fix: Save changes before process document.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Nov 13, 2024
1 parent 4de4aef commit bc2bd5d
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/api/ADempiere/userInterface/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function createEntity({
* @param {object} keyColumns
*/
export function updateEntity({
reccordId,
recordId,
tabId,
recordAttributes = {},
keyColumns = {}
Expand All @@ -94,7 +94,7 @@ export function updateEntity({
...keyColumns
}
return request({
url: `/user-interface/entities/${tabId}/${reccordId}`,
url: `/user-interface/entities/${tabId}/${recordId}`,
method: 'patch',
data: {
attributes: attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,20 @@ export default defineComponent({
return isExistsChanges.value
})

const reccordId = computed(() => {
const recordId = computed(() => {
const { table } = tabAttributes.value
const { key_columns, table_name } = table
const currentReccord = store.getters.getTabCurrentRow({
containerUuid: tabAttributes.value.containerUuid
})
if (!isEmptyValue(currentReccord[table_name + '_ID'])) return currentReccord[table_name + '_ID']
if (!isEmptyValue(key_columns)) return currentReccord[key_columns[key_columns.length - 1]]
return 1
if (!isEmptyValue(currentReccord[table_name + '_ID'])) {
return currentReccord[table_name + '_ID']
}
if (!isEmptyValue(key_columns)) {
const keyIndex = key_columns.length - 1
return currentReccord[key_columns.at(keyIndex)]
}
return -1
})

function saveChanges() {
Expand Down Expand Up @@ -150,7 +155,7 @@ export default defineComponent({
tabId: tabAttributes.value.internal_id,
tableName: tabAttributes.value.table_name,
recordUuid: recordUuid.value,
reccordId: reccordId.value
recordId: recordId.value
})
.then(response => {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
type="primary"
class="button-base-icon"
icon="el-icon-check"
@click="sendAction()"
@click="startDocumentAction()"
/>
</div>
</el-popover>
Expand All @@ -131,7 +131,10 @@ import language from '@/lang'
import store from '@/store'

// Constants
import { DOCUMENT_ACTION, DOCUMENT_STATUS } from '@/utils/ADempiere/constants/systemColumns'
import {
COLUMNNAME_DocAction, COLUMNNAME_DocStatus,
LOG_COLUMNS_NAME_LIST
} from '@/utils/ADempiere/constants/systemColumns'
import { DISPLAY_COLUMN_PREFIX } from '@/utils/ADempiere/dictionaryUtils'

// Components and Mixins
Expand All @@ -144,6 +147,7 @@ import {
refreshRecord
} from '@/utils/ADempiere/dictionary/window'
import { isRunableDocumentAction } from '@/utils/ADempiere/dictionary/workflow'
import { showMessage } from '@/utils/ADempiere/notification'

export default defineComponent({
name: 'DocumentAction',
Expand Down Expand Up @@ -204,23 +208,23 @@ export default defineComponent({
return store.getters.getValueOfFieldOnContainer({
parentUuid: props.parentUuid,
containerUuid,
columnName: DOCUMENT_STATUS
columnName: COLUMNNAME_DocStatus
})
})

const currentRecordDocumentAction = computed(() => {
return store.getters.getValueOfFieldOnContainer({
parentUuid: props.parentUuid,
containerUuid,
columnName: DOCUMENT_ACTION
columnName: COLUMNNAME_DocAction
})
})

const currentRecordDocumentActionDisplayValue = computed(() => {
return store.getters.getValueOfFieldOnContainer({
containerUuid: props.parentUuid, // tab uuid
// containerUuid,
columnName: DISPLAY_COLUMN_PREFIX + DOCUMENT_ACTION
columnName: DISPLAY_COLUMN_PREFIX + COLUMNNAME_DocAction
})
})

Expand Down Expand Up @@ -254,7 +258,7 @@ export default defineComponent({
if (isEmptyValue(defaultDocumentAction.value)) {
return store.getters.getValueOfFieldOnContainer({
containerUuid: props.tabAttributes.uuid,
columnName: DOCUMENT_ACTION
columnName: COLUMNNAME_DocAction
})
}
return defaultDocumentAction.value.value
Expand All @@ -279,7 +283,7 @@ export default defineComponent({
const currentDocStatusDisplayedValue = computed(() => {
const displayedValue = store.getters.getValueOfFieldOnContainer({
containerUuid,
columnName: DISPLAY_COLUMN_PREFIX + DOCUMENT_STATUS
columnName: DISPLAY_COLUMN_PREFIX + COLUMNNAME_DocStatus
})
if (!isEmptyValue(displayedValue)) {
return displayedValue
Expand Down Expand Up @@ -385,9 +389,69 @@ export default defineComponent({
store.dispatch('fieldListInfo', { info })
}

function sendAction() {
const isExistsChanges = computed(() => {
const persistenceValues = store.getters.getPersistenceAttributesChanges({
parentUuid: props.parentUuid,
containerUuid: props.tabAttributes.uuid,
recordUuid: recordUuid.value
})
return !isEmptyValue(persistenceValues)
})

const emptyMandatoryFields = computed(() => {
return store.getters.getTabFieldsEmptyMandatory({
parentUuid: props.parentUuid,
containerUuid: props.tabAttributes.uuid,
formatReturn: false
}).filter(itemField => {
// omit send to server (to create or update) columns manage by backend
return itemField.is_always_updateable ||
!LOG_COLUMNS_NAME_LIST.includes(itemField.columnName)
}).map(itemField => {
return itemField.name
})
})

function startDocumentAction() {
isVisibleDocAction.value = false
isLoadingActions.value = true

if (isExistsChanges.value) {
const emptyMandatory = emptyMandatoryFields.value.join(', ')
if (!isEmptyValue(emptyMandatory)) {
showMessage({
message: language.t('notifications.mandatoryFieldMissing') + emptyMandatory,
type: 'info'
})
isLoadingActions.value = false
return
}

return store.dispatch('flushPersistenceQueue', {
parentUuid: props.parentUuid,
containerUuid: props.tabAttributes.uuid,
tabId: props.tabAttributes.internal_id,
tableName: props.tabAttributes.table_name,
recordUuid: recordUuid.value,
recordId: recordId.value
})
.then(response => {
processDocumentWithAction()
})
.catch(error => {
isLoadingActions.value = false
// console.error('Error saving record', error.message)
showMessage({
message: error.message,
type: 'error'
})
})
}
processDocumentWithAction()
}

function processDocumentWithAction() {
isLoadingActions.value = true
store.dispatch('runDocumentActionOnServer', {
parentUuid: props.parentUuid,
containerUuid,
Expand Down Expand Up @@ -476,7 +540,7 @@ export default defineComponent({
// Methods
displayDocumentActions,
handleCommandActions,
sendAction,
startDocumentAction,
message
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ADempiere/TabManager/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export default defineComponent({
return {}
})

const reccordId = computed(() => {
const recordId = computed(() => {
if (isEmptyValue(currentTabPanelInfo.value)) return 1
const { table } = currentTabPanelInfo.value
const { key_columns, table_name } = table
Expand Down Expand Up @@ -1053,7 +1053,7 @@ export default defineComponent({
tabId: currentTab.internal_id,
tableName: currentTab.table_name,
recordUuid: undefined,
reccordId: -1
recordId: -1
})
.then(response => {
const {
Expand Down Expand Up @@ -1147,7 +1147,7 @@ export default defineComponent({
containerInfo,
currentTabPanelInfo,
emptyMandatoryFields,
reccordId,
recordId,
// methods
theAction,
handleClick,
Expand Down
7 changes: 5 additions & 2 deletions src/store/modules/ADempiere/documentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import Vue from 'vue'

// Constants
import { DOCUMENT_STATUS } from '@/utils/ADempiere/constants/systemColumns'
import {
COLUMNNAME_DocStatus
} from '@/utils/ADempiere/constants/systemColumns'

// API Request Methods
import {
Expand Down Expand Up @@ -177,6 +179,7 @@ const documentManager = {

if (isError) {
type = 'error'
console.warn(`Error Run Doc Action: ${text}.`)
}

showNotification({
Expand Down Expand Up @@ -204,7 +207,7 @@ const documentManager = {
const documentStatus = getters.getValueOfFieldOnContainer({
// parentUuid: parentUuid,
containerUuid: containerUuid,
columnName: DOCUMENT_STATUS
columnName: COLUMNNAME_DocStatus
})

if (!isEmptyValue(documentStatus)) {
Expand Down
6 changes: 3 additions & 3 deletions src/store/modules/ADempiere/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const persistence = {
parentUuid,
containerUuid,
tabId,
reccordId,
recordId,
tableName,
recordUuid,
attributesList
Expand Down Expand Up @@ -281,7 +281,7 @@ const persistence = {
if (!isEmptyValue(recordUuid) && recordUuid !== 'create-new') {
// Update existing entity
// if (key_columns.length > 1) {
// reccordId = 0
// recordId = 0
// }
const recordAttributes = {}
attributesList.forEach(attribute => {
Expand Down Expand Up @@ -321,7 +321,7 @@ const persistence = {
})
}
return updateEntity({
reccordId,
recordId,
tabId,
recordUuid,
recordAttributes,
Expand Down
8 changes: 8 additions & 0 deletions src/utils/ADempiere/constants/systemColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ export const VALUE = 'Value'

export const DOCUMENT_NO = 'DocumentNo'

/**
* @deprecated
*/
export const DOCUMENT_STATUS = 'DocStatus'
export const COLUMNNAME_DocStatus = 'DocStatus'

/**
* @deprecated
*/
export const DOCUMENT_ACTION = 'DocAction'
export const COLUMNNAME_DocAction = 'DocAction'

export const STD_PRECISION = 'StdPrecision'

Expand Down

0 comments on commit bc2bd5d

Please sign in to comment.