[REF]Refactoring code for date_start and date_end validation

This commit is contained in:
Fabien BOURGEOIS 2017-11-15 15:03:12 +01:00
parent e26e6fd1c7
commit f0e9dbab4d
1 changed files with 4 additions and 13 deletions

View File

@ -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):