From 4ffedc5add821b0b7e9b387aa93a7ffef9b28c0e Mon Sep 17 00:00:00 2001 From: Fabien Bourgeois Date: Sun, 10 Jul 2016 07:39:38 +0200 Subject: [PATCH] [IMP]GOLEM Activity default season at creation --- golem_activity/models/golem_activity.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/golem_activity/models/golem_activity.py b/golem_activity/models/golem_activity.py index 2f75994..f95db0b 100644 --- a/golem_activity/models/golem_activity.py +++ b/golem_activity/models/golem_activity.py @@ -39,8 +39,15 @@ class GolemActivity(models.Model): default_code = fields.Char(copy=True) # Own fields - season_id = fields.Many2one('golem.season', string='Season', - copy=False, required=True) + + @api.model + def _default_season(self): + """ Get default season """ + domain = [('is_default', '=', True)] + return self.env['golem.season'].search(domain) + + season_id = fields.Many2one('golem.season', string='Season', copy=False, + required=True, default=_default_season) animator_id = fields.Many2one('res.partner', string='Animator', domain=[('is_company', '=', False)]) date_start = fields.Date('Start date', copy=False) @@ -70,8 +77,7 @@ class GolemActivity(models.Model): @api.depends('season_id') def _compute_is_current(self): """ Checks if activity is active for current season """ - domain = [('is_default', '=', True)] - default_season = self.env['golem.season'].search(domain) + default_season = self._default_season() for a in self: a.is_current = (default_season == a.season_id)