Files
Odoo-18.0-20251222/account_financial_report/models/account_group.py
Pedro M. Baeza 072859bcb7 [FIX] account_financial_report: 2 things:
* Fix account group level computation

  Depends was not correct for recomputing when needed + better algorithm

* Make hide details on 0 work properly

  * Passing values to general ledger was stripping some correct records
  * Computed field for hiding lines doesn't have proper dependencies nor is not
    taking into account float currency accuracy
2024-11-29 15:38:40 +07:00

47 lines
1.5 KiB
Python

# ?? 2018 Forest and Biomass Romania SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class AccountGroup(models.Model):
_inherit = 'account.group'
group_child_ids = fields.One2many(
comodel_name='account.group',
inverse_name='parent_id',
string='Child Groups')
level = fields.Integer(
string='Level',
compute='_compute_level',
store=True)
account_ids = fields.One2many(
comodel_name='account.account',
inverse_name='group_id',
string="Accounts")
compute_account_ids = fields.Many2many(
'account.account',
compute='_compute_group_accounts',
string="Accounts", store=True)
@api.multi
@api.depends('parent_id', 'parent_id.level')
def _compute_level(self):
for group in self:
if not group.parent_id:
group.level = 0
else:
group.level = group.parent_id.level + 1
@api.multi
@api.depends('code_prefix', 'account_ids', 'account_ids.code',
'group_child_ids', 'group_child_ids.account_ids.code')
def _compute_group_accounts(self):
account_obj = self.env['account.account']
accounts = account_obj.search([])
for group in self:
prefix = group.code_prefix if group.code_prefix else group.name
gr_acc = accounts.filtered(
lambda a: a.code.startswith(prefix)).ids
group.compute_account_ids = [(6, 0, gr_acc)]