[IMP] account: implement account.account hierarchies
This information will be used by account.report to render accounts in hierarchies. Was PR #17367
This commit is contained in:
@@ -74,6 +74,7 @@ class AccountAccount(models.Model):
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True,
|
||||
default=lambda self: self.env['res.company']._company_default_get('account.account'))
|
||||
tag_ids = fields.Many2many('account.account.tag', 'account_account_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting")
|
||||
group_id = fields.Many2one('account.group')
|
||||
|
||||
_sql_constraints = [
|
||||
('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !')
|
||||
@@ -112,6 +113,22 @@ class AccountAccount(models.Model):
|
||||
if self.internal_type in ('receivable', 'payable'):
|
||||
self.reconcile = True
|
||||
|
||||
@api.onchange('code')
|
||||
def onchange_code(self):
|
||||
AccountGroup = self.env['account.group']
|
||||
|
||||
group = False
|
||||
code_prefix = self.code
|
||||
|
||||
# find group with longest matching prefix
|
||||
while code_prefix:
|
||||
matching_group = AccountGroup.search([('code_prefix', '=', code_prefix)], limit=1)
|
||||
if matching_group:
|
||||
group = matching_group
|
||||
break
|
||||
code_prefix = code_prefix[:-1]
|
||||
self.group_id = group
|
||||
|
||||
@api.multi
|
||||
@api.depends('name', 'code')
|
||||
def name_get(self):
|
||||
@@ -177,6 +194,27 @@ class AccountAccount(models.Model):
|
||||
}
|
||||
|
||||
|
||||
class AccountGroup(models.Model):
|
||||
_name = "account.group"
|
||||
|
||||
_parent_store = True
|
||||
_order = 'code_prefix'
|
||||
|
||||
parent_id = fields.Many2one('account.group', index=True, ondelete='cascade')
|
||||
parent_left = fields.Integer('Left Parent', index=True)
|
||||
parent_right = fields.Integer('Right Parent', index=True)
|
||||
name = fields.Char(required=True)
|
||||
code_prefix = fields.Char()
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
for group in self:
|
||||
name = group.name
|
||||
if group.code_prefix:
|
||||
name = group.code_prefix + ' ' + name
|
||||
result.append((group.id, name))
|
||||
return result
|
||||
|
||||
class AccountJournal(models.Model):
|
||||
_name = "account.journal"
|
||||
_description = "Journal"
|
||||
|
||||
@@ -71,6 +71,7 @@ class AccountAccountTemplate(models.Model):
|
||||
help="This optional field allow you to link an account template to a specific chart template that may differ from the one its root parent belongs to. This allow you "
|
||||
"to define chart templates that extend another and complete it with few new accounts (You don't need to define the whole structure that is common to both several times).")
|
||||
tag_ids = fields.Many2many('account.account.tag', 'account_account_template_account_tag', string='Account tag', help="Optional tags you may want to assign for custom reporting")
|
||||
group_id = fields.Many2one('account.group')
|
||||
|
||||
@api.multi
|
||||
@api.depends('name', 'code')
|
||||
|
||||
@@ -12,6 +12,8 @@ access_account_account_manager,account.account,model_account_account,account.gro
|
||||
access_account_account,account.account,model_account_account,account.group_account_user,1,0,0,0
|
||||
access_account_account_user,account.account user,model_account_account,base.group_user,1,0,0,0
|
||||
access_account_account_partner_manager,account.account partner manager,model_account_account,base.group_partner_manager,1,0,0,0
|
||||
access_account_group_manager,account.group,model_account_group,account.group_account_manager,1,1,1,1
|
||||
access_account_group,account.group,model_account_group,account.group_account_user,1,0,0,0
|
||||
access_account_tax,account.tax,model_account_tax,account.group_account_invoice,1,0,0,0
|
||||
access_account_account_template,account.account.template,model_account_account_template,account.group_account_manager,1,1,1,1
|
||||
access_account_chart_template,account.chart.template,model_account_chart_template,account.group_account_manager,1,1,1,1
|
||||
|
||||
|
@@ -17,8 +17,8 @@
|
||||
<field name="name"/>
|
||||
<field name="user_type_id" widget="selection"/>
|
||||
<field name="tax_ids" widget="many2many_tags"/>
|
||||
<field name="tag_ids" widget="many2many_tags" domain="[('applicability', '!=', 'taxes')]" context="{'default_applicability': 'accounts'}" options="
|
||||
{'no_create_edit': True}"/>
|
||||
<field name="tag_ids" widget="many2many_tags" domain="[('applicability', '!=', 'taxes')]" context="{'default_applicability': 'accounts'}" options="{'no_create_edit': True}"/>
|
||||
<field name="group_id"/>
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
<field name="currency_id" options="{'no_create': True}" groups="base.group_multi_currency"/>
|
||||
<field name="internal_type" invisible="1" readonly="1"/>
|
||||
@@ -2167,5 +2167,41 @@
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_action_manual_reconciliation" parent="menu_finance_entries" action="action_manual_reconciliation" sequence="25"/>
|
||||
|
||||
<record id="view_account_group_form" model="ir.ui.view">
|
||||
<field name="name">account.group.form</field>
|
||||
<field name="model">account.group</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Account Group">
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="code_prefix"/>
|
||||
<field name="parent_id"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_account_group_tree" model="ir.ui.view">
|
||||
<field name="name">account.group.tree</field>
|
||||
<field name="model">account.group</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Account Group">
|
||||
<field name="code_prefix"/>
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_account_group_tree" model="ir.actions.act_window">
|
||||
<field name="name">Account Group</field>
|
||||
<field name="res_model">account.group</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_account_group" name="Groups"
|
||||
parent="account.account_account_menu"
|
||||
action="account.action_account_group_tree" sequence="110"/>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user