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.

46 lines
1.5 KiB

  1. # © 2018 Forest and Biomass Romania SA
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. class AccountGroup(models.Model):
  5. _inherit = 'account.group'
  6. group_child_ids = fields.One2many(
  7. comodel_name='account.group',
  8. inverse_name='parent_id',
  9. string='Child Groups')
  10. level = fields.Integer(
  11. string='Level',
  12. compute='_compute_level',
  13. store=True)
  14. account_ids = fields.One2many(
  15. comodel_name='account.account',
  16. inverse_name='group_id',
  17. string="Accounts")
  18. compute_account_ids = fields.Many2many(
  19. 'account.account',
  20. compute='_compute_group_accounts',
  21. string="Compute accounts", store=True)
  22. @api.multi
  23. @api.depends('parent_id', 'parent_id.level')
  24. def _compute_level(self):
  25. for group in self:
  26. if not group.parent_id:
  27. group.level = 0
  28. else:
  29. group.level = group.parent_id.level + 1
  30. @api.multi
  31. @api.depends('code_prefix', 'account_ids', 'account_ids.code',
  32. 'group_child_ids', 'group_child_ids.account_ids.code')
  33. def _compute_group_accounts(self):
  34. account_obj = self.env['account.account']
  35. accounts = account_obj.search([])
  36. for group in self:
  37. prefix = group.code_prefix if group.code_prefix else group.name
  38. gr_acc = accounts.filtered(
  39. lambda a: a.code.startswith(prefix)).ids
  40. group.compute_account_ids = [(6, 0, gr_acc)]