From f1a4380a8546caab0fbbea38af470733dbe8a168 Mon Sep 17 00:00:00 2001 From: michel Date: Thu, 11 Jan 2018 14:51:18 +0100 Subject: [PATCH] [TMP] load membership type date if exist --- golem_season/models/golem_season.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/golem_season/models/golem_season.py b/golem_season/models/golem_season.py index be94f66..ebdf2a5 100644 --- a/golem_season/models/golem_season.py +++ b/golem_season/models/golem_season.py @@ -30,7 +30,7 @@ class GolemSeason(models.Model): name = fields.Char('Season name', copy=False) membership_id = fields.Many2one('product.template', 'Membership type', - domain="[('membership', '=', True)]" ) + domain="[('membership', '=', True)]") member_counter = fields.Integer('Counter for member number generation', @@ -38,6 +38,16 @@ class GolemSeason(models.Model): date_start = fields.Date('Period start') date_end = fields.Date('Period end') + @api.onchange('membership_id') + def _onchange_season_dates(self): + """ Sets defaults dates according to membership type """ + for activity in self: + if activity.membership_id: + if not activity.date_start: + activity.date_start = activity.membership_id.membership_date_from + if not activity.date_end: + activity.date_end = activity.membership_id.membership_date_to + @api.constrains('date_start', 'date_end') def _check_period(self): """ Check if end date if after start date and if there is no conflict