Skip to content

Commit

Permalink
fix: Save and set Accouting Combination field.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt committed Sep 14, 2024
1 parent c2685d9 commit 60b546b
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 70 deletions.
5 changes: 3 additions & 2 deletions src/api/ADempiere/userInterface/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,21 @@ export function createEntity({
* Update Tab Entity
* @param {number} tabId
* @param {object} recordAttributes
* @param {object} keyColumns
*/
export function updateEntity({
reccordId,
tabId,
recordAttributes,
keyColumnsList
keyColumns
}) {
return request({
url: `/user-interface/entities/${tabId}/${reccordId}`,
method: 'patch',
data: {
attributes: {
...recordAttributes,
...keyColumnsList
...keyColumns
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export default defineComponent({
*/

function showList(isShow) {
if (isShow && isEmptyValue(optionsList.value)) filterSearch(displayValue.value)
if (isShow && isEmptyValue(optionsList.value)) {
filterSearch(displayValue.value)
}
}

/**
Expand Down Expand Up @@ -157,7 +159,9 @@ export default defineComponent({
})
.then(response => {
const { records } = response
if (isEmptyValue(records)) return
if (isEmptyValue(records)) {
return
}
optionsList.value = records.map(list => {
return {
...list,
Expand Down Expand Up @@ -198,7 +202,9 @@ export default defineComponent({
})
.then(response => {
const { records } = response
if (isEmptyValue(records)) return
if (isEmptyValue(records)) {
return
}
optionsList.value = records.map(list => {
return {
...list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import {
DISPLAY_COLUMN_PREFIX
} from '@/utils/ADempiere/dictionaryUtils'

// Utils and Helper Methods
import {
generateDisplayedValue
} from '@/utils/ADempiere/dictionary/field/accoutingCombination.js'

export default {
name: 'mixinAccountingCombination',

Expand Down Expand Up @@ -102,25 +107,21 @@ export default {
* Get custom displayed value
* @returns {string}
*/
generateDisplayedValue(recordRow) {
// generate with standard columns
const { Combination } = recordRow

return Combination
},
generateDisplayedValue,
/**
* @overwrite
* Set custom row on fields values
* @returns {string}
*/
setValues(rowData) {
const { C_ValidCombination_ID: value, UUID: uuid } = rowData
const displayedValue = this.generateDisplayedValue(rowData)
const displayValue = this.generateDisplayedValue(rowData)

// set ID value
this.value = value
// set display column (name) value
this.displayedValue = displayedValue
this.displayedValue = displayValue

// set UUID value
this.uuidValue = uuid

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ import {
ref
} from '@vue/composition-api'

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

// Api
Expand All @@ -179,8 +180,14 @@ import {
} from '@/api/ADempiere/fields/generalGedger'

// Constants
import {
DISPLAY_COLUMN_PREFIX,
UNIVERSALLY_UNIQUE_IDENTIFIER_COLUMN_SUFFIX
} from '@/utils/ADempiere/dictionaryUtils'
import { TEXT } from '@/utils/ADempiere/references'
import { ACCOUTING_COMBINATIONS_LIST_FORM, COLUMN_NAME } from '@/utils/ADempiere/dictionary/field/accoutingCombination.js'
import {
ACCOUTING_COMBINATIONS_LIST_FORM, COLUMN_NAME
} from '@/utils/ADempiere/dictionary/field/accoutingCombination.js'

// Components and Mixins
import CellDisplayInfo from '@/components/ADempiere/DataTable/Components/CellDisplayInfo.vue'
Expand All @@ -192,9 +199,11 @@ import { ORGANIZATION } from '@/utils/ADempiere/constants/systemColumns'

// Utils and Helper Methods
import { isEmptyValue, isSameValues } from '@/utils/ADempiere/valueUtils'
import {
generateDisplayedValue
} from '@/utils/ADempiere/dictionary/field/accoutingCombination.js'
import { containerManager as containerManagerForm } from '@/utils/ADempiere/dictionary/form'
import { showMessage } from '@/utils/ADempiere/notification'
import language from '@/lang'

export default defineComponent({
name: 'TableQueryCriteria',
Expand Down Expand Up @@ -245,7 +254,9 @@ export default defineComponent({
// Computed
const title = computed(() => {
let title = props.metadata.panelName
if (!isEmptyValue(props.metadata.panelName) && !isSameValues(props.metadata.panelName, props.metadata.name)) title += ` (${props.metadata.name})`
if (!isEmptyValue(props.metadata.panelName) && !isSameValues(props.metadata.panelName, props.metadata.name)) {
title += ` (${props.metadata.name})`
}
return title
})

Expand Down Expand Up @@ -275,7 +286,9 @@ export default defineComponent({
})

const organizationId = computed(() => {
if (isEmptyValue(fieldsListElements.value)) return setValuesCombinations.value['AD_Org_ID']
if (isEmptyValue(fieldsListElements.value)) {
return setValuesCombinations.value[ORGANIZATION]
}
return store.getters.getFieldsValue(ORGANIZATION)
})

Expand All @@ -290,7 +303,9 @@ export default defineComponent({
})

const filtersAccount = computed(() => {
if (isEmptyValue(store.getters.getFiltersAccount)) return null
if (isEmptyValue(store.getters.getFiltersAccount)) {
return null
}
return JSON.stringify(store.getters.getFiltersAccount)
})

Expand Down Expand Up @@ -413,11 +428,12 @@ export default defineComponent({
}

function saveAccoutingCombination() {
const currentValue = store.getters.getValueOfField({
containerUuid: props.metadata.containerUuid,
columnName: props.metadata.columnName
})
store.dispatch('saveAccountCombinations', {
id: store.getters.getValueOfField({
containerUuid: props.metadata.containerUuid,
columnName: props.metadata.columnName
}),
id: currentValue,
organizationId: store.getters.getFieldsValue(ORGANIZATION),
accountId: store.getters.getFieldsValue('Account_ID'),
parentUuid: props.metadata.parentUuid,
Expand Down Expand Up @@ -507,21 +523,66 @@ export default defineComponent({
}

function changeRecord() {
// if (!isEmptyValue(currentRow.value)) {
// store.dispatch('notifyFieldChange', {
// containerUuid: this.metadata.containerUuid,
// containerManager: this.containerManager,
// field: this.metadata,
// columnName: this.metadata.column_name,
// newValue: value
// })
// }
const {
parentUuid, containerUuid,
columnName, elementName, isSameColumnElement
} = props.metadata

const recordRow = currentRow.value
const {
UUID: uuid,
[COLUMN_NAME]: id
} = recordRow

const displayValue = generateDisplayedValue(recordRow)
// console.log(displayValue)

store.commit('updateValueOfField', {
parentUuid,
containerUuid,
columnName,
value: id
})
// set display column (name) value
store.commit('updateValueOfField', {
parentUuid,
containerUuid,
// DisplayColumn_'ColumnName'
columnName: DISPLAY_COLUMN_PREFIX + columnName,
value: displayValue
})
// set UUID value
store.commit('updateValueOfField', {
parentUuid,
containerUuid,
columnName: columnName + UNIVERSALLY_UNIQUE_IDENTIFIER_COLUMN_SUFFIX,
value: uuid
})

// update element column name (smart browse)
if (!isSameColumnElement) {
store.commit('updateValueOfField', {
parentUuid,
containerUuid,
columnName: elementName,
value: id
})
// set display column (name) value
store.commit('updateValueOfField', {
parentUuid,
containerUuid,
// DisplayColumn_'ColumnName'
columnName: DISPLAY_COLUMN_PREFIX + elementName,
value: displayValue
})
}

store.dispatch('notifyFieldChange', {
containerUuid: props.metadata.containerUuid,
containerUuid: containerUuid,
containerManager: props.containerManager,
field: props.metadata,
columnName: props.metadata.columnName,
newValue: currentRow.value[tableNameAccounting.value + '_ID']
columnName: columnName,
newValue: id
})
closeList()
}
Expand All @@ -544,11 +605,12 @@ export default defineComponent({

function loadCombinations() {
isLoadingPanel.value = true
const currentValue = store.getters.getValueOfField({
containerUuid: props.metadata.containerUuid,
columnName: props.metadata.columnName
})
getAccountingCombination({
id: store.getters.getValueOfField({
containerUuid: props.metadata.containerUuid,
columnName: props.metadata.columnName
})
id: currentValue
})
.then(response => {
const { values, table_name } = response
Expand Down Expand Up @@ -579,18 +641,24 @@ export default defineComponent({
}

function valuesCombinations(field) {
if (isEmptyValue(setValuesCombinations.value)) return ''
if (isEmptyValue(setValuesCombinations.value)) {
return ''
}
return setValuesCombinations.value[field.columnName]
// return setValuesCombinations.value['DisplayColumn_' + field.columnName]
}

function setPageNumber(pageNumber) {
if (isEmptyValue(pageNumber)) return
if (isEmptyValue(pageNumber)) {
return
}
searchRecordsList(pageNumber)
}

watch(isLoadingTable, (newValue, oldValue) => {
if (newValue && newValue !== oldValue) searchRecordsList()
if (newValue && newValue !== oldValue) {
searchRecordsList()
}
})

getAccoutingElements()
Expand Down
13 changes: 12 additions & 1 deletion src/store/modules/ADempiere/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { getContextAttributes } from '@/utils/ADempiere/contextUtils/contextAttr
import {
isDateField, isDecimalField, isSupportLookup
} from '@/utils/ADempiere/references'
import { getTableKeyValues } from '@/utils/ADempiere/recordUtil'

const persistence = {
state: {
Expand Down Expand Up @@ -307,11 +308,21 @@ const persistence = {

recordAttributes[columnName] = currentValue
})
// table multi-keys
let keyColumns = {}
if (key_columns.length > 1) {
keyColumns = getTableKeyValues({
parentUuid,
containerUuid,
keyColumns: key_columns
})
}
return updateEntity({
reccordId,
tabId,
recordUuid,
recordAttributes
recordAttributes,
keyColumns
})
.then(response => {
// TODO: Get list record log
Expand Down
28 changes: 26 additions & 2 deletions src/utils/ADempiere/dictionary/field/accoutingCombination.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution
* Copyright (C) 2017-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com
* 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
Expand All @@ -16,8 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

// Utils and Helper Methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'

export const TABLE_NAME = 'C_ValidCombination'

export const COLUMN_NAME = 'C_ValidCombination_ID'

export const ACCOUTING_COMBINATIONS_LIST_FORM = 'Accouting-Combination-List'
export const ACCOUTING_COMBINATIONS_LIST_FORM = 'Accouting-Combinations-List'

/**
* Generate displayed value from values
* @param {Object} recordRow
* @returns {String}
*/
export function generateDisplayedValue(recordRow) {
const {
DisplayColumn_C_ValidCombination_ID: display_value
} = recordRow
let displayValue = display_value
if (!isEmptyValue(displayValue)) {
return displayValue
}

// generate with standard columns
const { Combination } = recordRow
displayValue = Combination

return displayValue
}
Loading

0 comments on commit 60b546b

Please sign in to comment.