From f0e9dbab4dc59b117f6dbb3d36a8a26f728cfce3 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Wed, 15 Nov 2017 15:03:12 +0100 Subject: [PATCH] [REF]Refactoring code for date_start and date_end validation --- models/event.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/models/event.py b/models/event.py index a663be4..811da8a 100644 --- a/models/event.py +++ b/models/event.py @@ -68,20 +68,11 @@ class Event(models.Model): raise models.ValidationError(_('You can have subscribed people ' 'if event is not confirmed yet')) - @api.constrains('date_end') - def _check_date_end(self): - """Test si la modification de la date n'est pas postérieur à la date de début""" + @api.constrains('date_start', 'date_end') + def _check_dates(self): + """Test si la modification de la date de début est infnérieure à la date de fin""" if self.date_start > self.date_end: - raise ValidationError( - _('Date most be supperior to to start date')) - - @api.constrains('date_start') - def _check_date_start(self): - """Test si la modification de la date de fin n'est pas anterieur à la date de début""" - if self.date_end < self.date_start: - raise ValidationError( - _('Date most be inferior to to end date')) - + raise ValidationError(_('End date most be supperior to to start date')) @api.depends('date_start', 'date_end') def _compute_duration(self):