compute root area

This commit is contained in:
Youssef Elouahby 2018-10-12 16:06:18 +01:00
parent 71f7299aaf
commit ace87392db
1 changed files with 14 additions and 2 deletions

View File

@ -22,6 +22,12 @@ from odoo import models, fields, api, _
from odoo.exceptions import UserError
_LOGGER = logging.getLogger(__name__)
def get_root_area(area_id):
""" Get root area """
if not area_id.parent_id:
return area_id
else:
return get_root_area(area_id.parent_id)
class PartnerArea(models.Model):
""" Partner Area """
@ -38,8 +44,14 @@ class PartnerArea(models.Model):
string="street list")
parent_id = fields.Many2one('golem.partner.area', string="Parent Territory",
domain="[('id', '!=', id)]")
sub_territorie_ids = fields.One2many('golem.partner.area', 'parent_id',
string="Sub Territories List")
root_id = fields.Many2one('golem.partner.area', compute="_compute_root_id",
string="Root area")
@api.depends('parent_id')
def _compute_root_id(self):
""" Compute root_id """
for area in self:
area.root_id = get_root_area(area)
class ResPartner(models.Model):