diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/account/static/src/js/account_selection.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/account/static/src/js/account_selection.js')
| -rw-r--r-- | addons/account/static/src/js/account_selection.js | 80 |
1 files changed, 80 insertions, 0 deletions
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 00000000..feee1c17 --- /dev/null +++ b/addons/account/static/src/js/account_selection.js @@ -0,0 +1,80 @@ +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: 'search_read', + kwargs: { + domain: [], + fields: ['id', 'internal_group', 'display_name'], + }, + }).then(function(arg) { + self.values = _.map(arg, v => [v['id'], v['display_name']]) + self.hierarchy_groups = [ + { + 'name': _t('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 => v['id'])}, + {'name': _t('Equity'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'equity'), v => v['id'])}, + ], + }, + { + 'name': _t('Profit & Loss'), + 'children': [ + {'name': _t('Income'), 'ids': _.map(_.filter(arg, v => v['internal_group'] == 'income'), v => v['id'])}, + {'name': _t('Expense'), 'ids': _.map(_.filter(arg, v => 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 = $('<optgroup/>').attr(({ + 'label': $('<div/>').html(' '.repeat(6 * level) + item['name']).text(), + })) + _.each(item['ids'], function(id) { + var value = _.find(self.values, v => v[0] == id) + optgroup.append($('<option/>', { + value: JSON.stringify(value[0]), + text: value[1], + })); + }) + el.append(optgroup) + if (item['children']) { + self._addHierarchy(el, item['children'], level + 1); + } + }) + } + }); + registry.add("account_hierarchy_selection", HierarchySelection); +}); |
