2023-06-19 11:07:39 -04:00
|
|
|
from odoo import models, fields, api, _, Command
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Partner(models.Model):
|
|
|
|
|
_inherit = 'res.partner'
|
|
|
|
|
|
2023-06-19 11:51:23 -04:00
|
|
|
root_ancestor = fields.Many2one(comodel_name='res.partner',
|
|
|
|
|
string='Root Ancestor',
|
2023-06-26 15:01:17 -04:00
|
|
|
compute='_compute_root_ancestor',
|
|
|
|
|
store=True,
|
|
|
|
|
recursive=True)
|
2023-06-19 11:51:23 -04:00
|
|
|
|
2023-06-26 15:01:17 -04:00
|
|
|
@api.depends('parent_id', 'parent_id.root_ancestor')
|
2023-06-19 11:51:23 -04:00
|
|
|
def _compute_root_ancestor(self):
|
|
|
|
|
for rec in self:
|
|
|
|
|
rec.root_ancestor = rec.parent_id and rec.parent_id.root_ancestor or rec
|