From 42cec4f0e1c8480eaa2d45d38f6c2f77734186de Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 11:37:16 +0100 Subject: [PATCH] check slot hours consistence --- .../models/golem_activity_registration_slot.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/golem_activity_registration_slot/models/golem_activity_registration_slot.py b/golem_activity_registration_slot/models/golem_activity_registration_slot.py index 183a539..332772f 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration_slot.py +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -33,3 +33,13 @@ class GolemActivityRegistrationSlot(models.Model): ondelete='cascade', index=True) hour_start = fields.Float('Start time') hour_stop = fields.Float('Stop time') + + @api.constrains('hour_start', 'hour_stop') + def check_slot_hours(self): + """ Check slot hours consistence """ + for slot in self: + if slot.hour_start < slot.activity_id.hour_start or \ + slot.hour_stop > slot.activity_id.hour_stop: + verr = _(u'Slot start and stop must be between activity start and' + ' activity stop.') + raise ValidationError(verr)