diff --git a/addons/account/models/account.py b/addons/account/models/account.py
index 4a2846255d2..55c44db7d53 100644
--- a/addons/account/models/account.py
+++ b/addons/account/models/account.py
@@ -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"
diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py
index a7db0c251fe..3164eb79b51 100644
--- a/addons/account/models/chart_template.py
+++ b/addons/account/models/chart_template.py
@@ -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')
diff --git a/addons/account/security/ir.model.access.csv b/addons/account/security/ir.model.access.csv
index a0955a5482c..233f9a1b36d 100644
--- a/addons/account/security/ir.model.access.csv
+++ b/addons/account/security/ir.model.access.csv
@@ -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
diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml
index 567b7098eae..3f7445e5c65 100644
--- a/addons/account/views/account_view.xml
+++ b/addons/account/views/account_view.xml
@@ -17,8 +17,8 @@
-
+
+
@@ -2167,5 +2167,41 @@
+
+
+ account.group.form
+ account.group
+
+
+
+
+
+
+ account.group.tree
+ account.group
+
+
+
+
+
+
+
+
+
+ Account Group
+ account.group
+ form
+ tree,form
+
+
+