Skip to content

Commit

Permalink
fix: Field accouting combination undo changes. (adempiere#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt authored Jan 26, 2023
1 parent c126ea1 commit b13b19b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 34 deletions.
78 changes: 45 additions & 33 deletions src/store/modules/ADempiere/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import { isEmptyValue, isSameValues } from '@/utils/ADempiere/valueUtils.js'
import { showMessage } from '@/utils/ADempiere/notification.js'
import { getContextDefaultValue } from '@/utils/ADempiere/dictionaryUtils.js'
import { isSupportLookup } from '@/utils/ADempiere/references'

const persistence = {
state: {
Expand Down Expand Up @@ -96,11 +97,10 @@ const persistence = {
// clear old values
clearPersistenceQueue(state, {
containerUuid,
recordUuid,
logs = {}
recordUuid
}) {
const key = containerUuid + '_' + recordUuid
Vue.set(state.persistence, key, logs)
Vue.set(state.persistence, key, {})

// state.persistence[containerUuid] = {
// [recordUuid]: new Map()
Expand Down Expand Up @@ -138,6 +138,27 @@ const persistence = {
oldValue = defaultValue
}

if (isSupportLookup(field.displayType)) {
let displayedValue
if (!isEmptyValue(currentRecord)) {
displayedValue = currentRecord[field.displayColumnName]
}
if (isEmptyValue(currentRecord) || oldValue === value) {
const defaultValue = getContextDefaultValue({
...field,
columnName: field.displayColumnName
})
displayedValue = defaultValue
}
commit('addChangeToPersistenceQueue', {
containerUuid,
recordUuid: getters.getUuidOfContainer(field.containerUuid),
columnName: field.displayColumnName,
oldValue: displayedValue,
value: undefined
})
}

commit('addChangeToPersistenceQueue', {
containerUuid,
recordUuid: getters.getUuidOfContainer(field.containerUuid),
Expand Down Expand Up @@ -367,55 +388,45 @@ const persistence = {
recordUuid
})

// set old value as current value
const LastChange = valuesChanges[valuesChanges.length - 1]
const { columnName, oldValue } = LastChange
valuesChanges.forEach(changes => {
const { columnName, oldValue } = changes

commit('updateValueOfField', {
parentUuid,
containerUuid,
columnName,
recordUuid,
value: oldValue
}, {
root: true
commit('updateValueOfField', {
parentUuid,
containerUuid,
columnName,
recordUuid,
value: oldValue
}, {
root: true
})
})

dispatch('clearPersistenceQueue', {
containerUuid,
columnName,
recordUuid,
logs: valuesChanges
recordUuid
})
},

// clear old values
clearPersistenceQueue({ commit }, {
containerUuid,
recordUuid,
columnName,
logs
recordUuid
}) {
let changeLogs
if (!isEmptyValue(logs)) {
changeLogs = logs.filter(log => log.columnName !== columnName)
}

commit('clearPersistenceQueue', {
containerUuid,
recordUuid,
columnName,
logs: changeLogs
recordUuid
})
}
},

getters: {
getPersistenceAttributes: (state) => ({ containerUuid, recordUuid }) => {
const key = containerUuid + '_' + recordUuid
const changes = state.persistence[key]

if (!isEmptyValue(state.persistence[key])) {
return Object.values(state.persistence[key])
if (!isEmptyValue(changes)) {
return Object.values(changes)
// only changes
.filter(attribute => {
const { value, oldValue } = attribute
Expand All @@ -438,8 +449,9 @@ const persistence = {
recordUuid
}) => {
const key = containerUuid + '_' + recordUuid
const changes = state.persistence[key]

if (!isEmptyValue(state.persistence[key])) {
if (!isEmptyValue(changes)) {
if (isEmptyValue(recordUuid)) {
const defaultRow = rootGetters.getTabParsedDefaultValue({
parentUuid,
Expand All @@ -448,15 +460,15 @@ const persistence = {
formatToReturn: 'object'
})

return Object.values(state.persistence[key])
return Object.values(changes)
// only changes with default value
.filter(attribute => {
const { value, columnName } = attribute
return !isSameValues(value, defaultRow[columnName])
})
}

return Object.values(state.persistence[key])
return Object.values(changes)
// only changes
.filter(attribute => {
const { value, oldValue } = attribute
Expand Down

0 comments on commit b13b19b

Please sign in to comment.