mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Installation ============ If you have already the chart of accounts loaded on your company, you will need to update it through the module `account_chart_update`. Follow the instructions on that module for that. Configuration ============= To configure account groups, you need to: * Be "Account / Adviser" role. * Go to *Invoicing > Configuration > Accounts Groups*. * Create or modify existing groups. For assigning groups to account templates, you have to: * Set the group on your account chart module or extension. * Or develop/create UI access. When you have groups on your account templates, you can load a chart template for a new company, and they will be transferred to created accounts. Usage ===== For assigning groups to accounts: * Go to *Invoicing > Adviser > Chart of Accounts*. * Edit one account and set "Group" field.
75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
# coding: utf-8
|
|
# Copyright 2018 Tecnativa - Pedro M. Baeza
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
from odoo import api, fields, models
|
|
from odoo.osv import expression
|
|
|
|
|
|
class AccountGroup(models.Model):
|
|
_name = 'account.group'
|
|
_parent_store = True
|
|
_parent_order = 'name'
|
|
_order = 'code_prefix'
|
|
|
|
parent_id = fields.Many2one(
|
|
comodel_name='account.group',
|
|
string="Parent",
|
|
index=True,
|
|
ondelete='cascade',
|
|
)
|
|
parent_left = fields.Integer(
|
|
string='Left Parent',
|
|
index=True,
|
|
)
|
|
parent_right = fields.Integer(
|
|
string='Right Parent',
|
|
index=True,
|
|
)
|
|
name = fields.Char(
|
|
required=True,
|
|
)
|
|
code_prefix = fields.Char()
|
|
account_ids = fields.One2many(
|
|
comodel_name='account.account',
|
|
inverse_name='group_id',
|
|
string='Accounts',
|
|
help="Assigned accounts.",
|
|
)
|
|
level = fields.Integer(
|
|
compute='_compute_level',
|
|
store=True,
|
|
)
|
|
|
|
@api.depends('parent_id')
|
|
def _compute_level(self):
|
|
for group in self:
|
|
level = 1
|
|
parent = group.parent_id
|
|
while parent:
|
|
level += 1
|
|
parent = parent.parent_id
|
|
group.level = level
|
|
|
|
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
|
|
|
|
@api.model
|
|
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
|
if not args:
|
|
args = []
|
|
criteria_operator = (
|
|
['|'] if operator not in expression.NEGATIVE_TERM_OPERATORS
|
|
else ['&', '!']
|
|
)
|
|
domain = criteria_operator + [
|
|
('code_prefix', '=ilike', name + '%'), ('name', operator, name)
|
|
]
|
|
return self.search(domain + args, limit=limit).name_get()
|