You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB

  1. # coding: utf-8
  2. # Copyright 2018 Eficent
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. class AccountGroup(models.Model):
  6. _inherit = 'account.group'
  7. group_child_ids = fields.One2many(
  8. comodel_name='account.group',
  9. inverse_name='parent_id',
  10. string='Child Groups')
  11. compute_account_ids = fields.Many2many(
  12. 'account.account',
  13. compute='_compute_group_accounts',
  14. string="Accounts", store=True)
  15. @api.multi
  16. @api.depends('code_prefix', 'account_ids', 'account_ids.code',
  17. 'group_child_ids', 'group_child_ids.account_ids.code')
  18. def _compute_group_accounts(self):
  19. account_obj = self.env['account.account']
  20. accounts = account_obj.search([])
  21. for group in self:
  22. prefix = group.code_prefix if group.code_prefix else group.name
  23. gr_acc = accounts.filtered(
  24. lambda a: a.code.startswith(prefix)).ids
  25. group.compute_account_ids = [(6, 0, gr_acc)]