[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) <qdp@openerp.com>
This commit is contained in:
wan
2019-08-29 15:07:47 +00:00
committed by qdp-odoo
parent 33354f71e1
commit 5aeec0c3dc
8 changed files with 83 additions and 6 deletions
@@ -69,6 +69,7 @@
</record>
<record model="account.account.type" id="data_unaffected_earnings">
<field name="name">Current Year Earnings</field>
<field name="internal_group">equity</field>
<field name="include_initial_balance" eval="True"/>
</record>
<record model="account.account.type" id="data_account_type_other_income">
+2 -1
View File
@@ -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')
@@ -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 = $('<optgroup/>').attr(({
'label': $('<div/>').html('&nbsp;&nbsp;'.repeat(3 * 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);
});
+1
View File
@@ -30,6 +30,7 @@
<script type="text/javascript" src="/account/static/src/js/section_and_note_fields_backend.js"></script>
<script type="text/javascript" src="/account/static/src/js/tours/account.js"></script>
<script type="text/javascript" src="/account/static/src/js/bills_tree_upload.js"/>
<script type="text/javascript" src="/account/static/src/js/account_selection.js"/>
</xpath>
</template>
+2 -2
View File
@@ -15,7 +15,7 @@
<group>
<field name="code" placeholder="code"/>
<field name="name"/>
<field name="user_type_id" widget="selection"/>
<field name="user_type_id" widget="account_hierarchy_selection"/>
<field name="tax_ids" widget="many2many_tags" domain="[('company_id','=',company_id)]" attrs="{'invisible': [('internal_group', '=', 'off_balance')]}"/>
<field name="tag_ids" widget="many2many_tags" domain="[('applicability', '!=', 'taxes')]" context="{'default_applicability': 'accounts'}" options="{'no_create_edit': True}"/>
<field name="group_id"/>
@@ -1397,7 +1397,7 @@ action = model.setting_init_bank_account_action()
<field name="name"/>
<field name="code"/>
<newline/>
<field name="user_type_id" widget="selection"/>
<field name="user_type_id" widget="account_hierarchy_selection"/>
<field name="currency_id" options="{'no_create': True}" groups="base.group_multi_currency"/>
<field name="tag_ids" domain="[('applicability', '!=', 'taxes')]" widget="many2many_tags" context="{'default_applicability': 'accounts'}"/>
<field name="reconcile"/>
+2 -1
View File
@@ -132,7 +132,8 @@ class TestPoSCommon(TransactionCase):
self.other_receivable_account = self.env['account.account'].create({
'name': 'Other Receivable',
'code': 'RCV00' ,
'user_type_id': self.env['account.account.type'].create({'name': 'RCV type', 'type': 'receivable'}).id,
'user_type_id': self.env['account.account.type'].create({'name': 'RCV type', 'type': 'receivable', 'internal_group': 'asset'}).id,
'internal_group': 'asset',
'reconcile': True,
})
+1 -1
View File
@@ -572,7 +572,7 @@ class TestSaleMrpFlow(common.SavepointCase):
self.company.anglo_saxon_accounting = True
self.partner = self.env.ref('base.res_partner_1')
self.category = self.env.ref('product.product_category_1').copy({'name': 'Test category','property_valuation': 'real_time', 'property_cost_method': 'fifo'})
account_type = self.env['account.account.type'].create({'name': 'RCV type', 'type': 'other'})
account_type = self.env['account.account.type'].create({'name': 'RCV type', 'type': 'other', 'internal_group': 'asset'})
self.account_receiv = self.env['account.account'].create({'name': 'Receivable', 'code': 'RCV00' , 'user_type_id': account_type.id, 'reconcile': True})
account_expense = self.env['account.account'].create({'name': 'Expense', 'code': 'EXP00' , 'user_type_id': account_type.id, 'reconcile': True})
account_output = self.env['account.account'].create({'name': 'Output', 'code': 'OUT00' , 'user_type_id': account_type.id, 'reconcile': True})
+2 -1
View File
@@ -35,7 +35,8 @@ class TestStockLandedCostsCommon(AccountingTestCase):
'code': "X1101",
'user_type_id': self.env['account.account.type'].create({
'name': 'Expenses',
'type': 'other'}).id,
'type': 'other',
'internal_group': 'liability'}).id,
'reconcile': True})
self.expenses_journal = self.env['account.journal'].create({
'name': 'Expenses - Test',