From 5d4b5d71c016796e896ea5391b30d076e14ae561 Mon Sep 17 00:00:00 2001 From: aliya Date: Mon, 11 Jul 2022 16:39:27 +0000 Subject: [PATCH] [FIX] account: fix the account selection widget After the change in account_type field in account.account the old selection widget didn't work. Fixing the selection widget and adding it back on acocunt_type field. As account types cannot be custom anymore, the account types within the hierarchy can be hardcoded. closes odoo/odoo#95821 Signed-off-by: Cedric Snauwaert --- .../static/src/js/account_selection.js | 119 ++++-------------- .../static/src/xml/account_type_selection.xml | 17 +++ .../account/views/account_account_views.xml | 6 +- .../views/account_chart_template_views.xml | 2 +- addons/account/wizard/setup_wizards_view.xml | 2 +- 5 files changed, 46 insertions(+), 100 deletions(-) create mode 100644 addons/account/static/src/xml/account_type_selection.xml diff --git a/addons/account/static/src/js/account_selection.js b/addons/account/static/src/js/account_selection.js index f93ba3f2342..99cd9b3782b 100644 --- a/addons/account/static/src/js/account_selection.js +++ b/addons/account/static/src/js/account_selection.js @@ -1,100 +1,31 @@ -odoo.define('account.hierarchy.selection', function (require) { -"use strict"; +/** @odoo-module **/ - var core = require('web.core'); - var relational_fields = require('web.relational_fields'); - var _t = core._t; - var registry = require('web.field_registry'); +import { qweb, _t } from 'web.core'; +import fieldRegistry from 'web.field_registry'; +import { FieldSelection } from 'web.relational_fields'; - var FieldSelection = relational_fields.FieldSelection; +export const HierarchySelection = FieldSelection.extend({ - var HierarchySelection = FieldSelection.extend({ - _renderEdit: function () { - var self = this; - var selectSuper = this._super; - var prom = Promise.resolve(); - if (!self.hierarchy_groups) { - prom = this._rpc({ - model: 'account.account.type', - method: 'search_read', - kwargs: { - domain: self.record.context && self.record.context.account_type_domain || [], - fields: ['id', 'internal_group', 'display_name'], - }, - }).then(function(arg) { - self.values = _.map(arg, v => [v['id'], v['display_name']]); - var unique_groups = _.uniq(_.map(arg, v => v['internal_group'])); - if (unique_groups.length > 1) { - var parent_lookup = { - 'bs': {'name': _t('Balance Sheet'), 'index': 0}, - 'pl': {'name': _t('Profit & Loss'), 'index': 1}, - } - var lookup = { - 'asset': {'parent': 'bs', 'name': _t('Assets')}, - 'liability': {'parent': 'bs', 'name': _t('Liabilities')}, - 'equity': {'parent': 'bs', 'name': _t('Equity')}, - 'income': {'parent': 'pl', 'name': _t('Income')}, - 'expense': {'parent': 'pl', 'name': _t('Expense')}, - } - var unique_parents = _.uniq(_.map(_.filter(unique_groups, u => u in lookup), g => lookup[g].parent)); - self.hierarchy_groups = []; - _.each(unique_parents, parent_id => { - var parent = parent_lookup[parent_id]; - self.hierarchy_groups.splice(parent.index, 0, {'name': parent.name, 'children': []}); - }); - var other_accounts_added = false; - _.each(unique_groups, g => { - if (g in lookup){ - var rec = lookup[g]; - self.hierarchy_groups[parent_lookup[rec.parent].index].children.push({ - 'name': rec['name'], - 'ids': _.map(_.filter(arg, v => v['internal_group'] == g), v => v['id']) - }); - } else if (!other_accounts_added){ - self.hierarchy_groups.push({ - 'name': _t('Other'), - 'ids': _.map(_.filter(arg, v => !_.keys(lookup).includes(v['internal_group'])), v => v['id']) - }); - other_accounts_added = true; - } - }) - } - }); - } + init: function () { + this._super.apply(this, arguments); + this.hierarchyGroups = [ + {name: _t('Balance Sheet')}, + {name: _t('Assets'), children: this.values.filter(x => x[0] && x[0].startsWith('asset'))}, + {name: _t('Liabilities'), children: this.values.filter(x => x[0] && x[0].startsWith('liability'))}, + {name: _t('Equity'), children: this.values.filter(x => x[0] && x[0].startsWith('equity'))}, + {name: _t('Profit & Loss')}, + {name: _t('Income'), children: this.values.filter(x => x[0] && x[0].startsWith('income'))}, + {name: _t('Expense'), children: this.values.filter(x => x[0] && x[0].startsWith('expense'))}, + {name: _t('Other'), children: this.values.filter(x => x[0] && x[0] == 'off_balance')}, + ]; + }, - Promise.resolve(prom).then(function() { - if (!self.hierarchy_groups) { - return selectSuper.apply(self, arguments); - } - self.$el.empty(); - self._addHierarchy(self.$el, self.hierarchy_groups, 0); - var value = self.value; - if (self.field.type === 'many2one' && value) { - value = value.data.id; - } - self.$el.val(JSON.stringify(value)); - }); - }, - _addHierarchy: function(el, group, level) { - var self = this; - _.each(group, function(item) { - var optgroup = $('').attr(({ - 'label': $('
').html(' '.repeat(6 * level) + item['name']).text(), - })) - _.each(item['ids'], function(id) { - var value = _.find(self.values, v => v[0] == id) - optgroup.append($('