From f0c95c2fdacd60c632f13a48a7f6b114a7008559 Mon Sep 17 00:00:00 2001 From: Nikos Tsirintanis Date: Tue, 30 Oct 2018 14:37:04 +0100 Subject: [PATCH] [FIX] computing domain for parent_id in date.range dynamically --- date_range/models/date_range.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/date_range/models/date_range.py b/date_range/models/date_range.py index 996d798..5ebd05e 100644 --- a/date_range/models/date_range.py +++ b/date_range/models/date_range.py @@ -35,8 +35,7 @@ class DateRange(models.Model): store=True, readonly=True) parent_id = fields.Many2one( - comodel_name='date.range', string="Parent", - index=1) + comodel_name='date.range', string="Parent", index=1) _sql_constraints = [ ('date_range_uniq', 'unique (name,type_id, company_id)', @@ -140,3 +139,16 @@ class DateRange(models.Model): self.ensure_one() return [(field_name, '>=', self.date_start), (field_name, '<=', self.date_end)] + + @api.multi + @api.onchange('type_id') + def onchange_type_id(self): + return { + 'domain': { + 'parent_id': [ + '|', + ('parent_type_id', '=', False), + ('type_id', '=', self.type_id.parent_type_id.id), + ] + } + }