From 5aeec0c3dcd8aa20293167073f3f4f5cec323b74 Mon Sep 17 00:00:00 2001 From: wan Date: Wed, 28 Aug 2019 09:05:29 +0000 Subject: [PATCH] [IMP] account: Hierarchy in account type selection field Task 2041865 We want to show a hierarchy to ease the account type selection (hack in the select widget) BALANCE SHEET ASSETS Fixed Assets Non-current Assets Current Assets Prepayments Receivable Bank and Cash LIABILITIES Equity Current Year Earnings Non-current Liabilities Current Liabilities Credit Card Payable PROFIT & LOSS Income Other Income Expenses Cost of Revenue Depreciation OTHER Off-Balance Sheet closes odoo/odoo#36170 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/data/data_account_type.xml | 1 + addons/account/models/account.py | 3 +- .../static/src/js/account_selection.js | 72 +++++++++++++++++++ addons/account/views/account.xml | 1 + addons/account/views/account_view.xml | 4 +- addons/point_of_sale/tests/common.py | 3 +- addons/sale_mrp/tests/test_sale_mrp_flow.py | 2 +- addons/stock_landed_costs/tests/common.py | 3 +- 8 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 addons/account/static/src/js/account_selection.js diff --git a/addons/account/data/data_account_type.xml b/addons/account/data/data_account_type.xml index ca4676f05f0..54ab23e605f 100644 --- a/addons/account/data/data_account_type.xml +++ b/addons/account/data/data_account_type.xml @@ -69,6 +69,7 @@ Current Year Earnings + equity diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 143ca388763..2d6ef5f10f5 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -41,7 +41,8 @@ class AccountAccountType(models.Model): ('expense', 'Expense'), ('off_balance', 'Off Balance'), ], string="Internal Group", - help="The 'Internal Group' is used to filter accounts based on the internal group set on the account type.") + required=True, + help="The 'Internal Group' is used to filter accounts based on the internal group set on the account type.") note = fields.Text(string='Description') diff --git a/addons/account/static/src/js/account_selection.js b/addons/account/static/src/js/account_selection.js new file mode 100644 index 00000000000..c000d5b6fd1 --- /dev/null +++ b/addons/account/static/src/js/account_selection.js @@ -0,0 +1,72 @@ +odoo.define('account.hierarchy.selection', function (require) { +"use strict"; + + var core = require('web.core'); + var relational_fields = require('web.relational_fields'); + var _t = core._t; + var registry = require('web.field_registry'); + + + var FieldSelection = relational_fields.FieldSelection; + + var qweb = core.qweb; + + var HierarchySelection = FieldSelection.extend({ + _renderEdit: function () { + var self = this; + var prom = Promise.resolve() + if (!self.hierarchy_groups) { + prom = this._rpc({ + model: 'account.account.type', + method: 'read', + args: [ + _.filter(_.map(this.values, v => v[0]), v => typeof v == 'number'), + ['internal_group'], + ], + }).then(function(arg) { + self.hierarchy_groups = [ + { + 'name': _('Balance Sheet'), + 'children': [ + {'name': _t('Assets'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'asset'), v => v['id'])}, + {'name': _t('Liabilities'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'liability' || v['internal_group'] == 'equity'), v => v['id'])}, + ] + }, + {'name': _t('Profit & Loss'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'income' || v['internal_group'] == 'expense'), v => v['id'])}, + {'name': _t('Other'), 'ids': _.map(_.filter(arg, v => !['asset', 'liability', 'equity', 'income', 'expense'].includes(v['internal_group'])), v => v['id'])}, + ] + }); + } + + Promise.resolve(prom).then(function() { + 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(3 * level) + item['name']).text(), + })) + _.each(item['ids'], function(id) { + var value = _.find(self.values, v => v[0] == id) + optgroup.append($('