From ce8a3c0adc0a23f22ff510e63f60e3aeeacff708 Mon Sep 17 00:00:00 2001 From: youssef Date: Sun, 4 Nov 2018 00:53:30 +0100 Subject: [PATCH] Calculate slots hours after slots reordering --- .../models/golem_activity_registration_slot.py | 16 ++++++++++++++++ 1 file changed, 16 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 f02d0d6..9683f65 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration_slot.py +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -40,8 +40,24 @@ class GolemActivityRegistrationSlot(models.Model): def check_slot_hours(self): """ Check slot hours consistency """ for slot in self: + if slot.hour_start >= slot.hour_stop: + verr = _(u'Slot start must be before slot stop') + raise ValidationError(verr) 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) + + @api.constrains('sequence') + def calculate_slot_hours(self): + """ Calcualte slot hours """ + slots = self.env['golem.activity.registration.slot'].search( + [('activity_id', '=', self[0].activity_id.id)], order='sequence') + for id_slot, slot in enumerate(slots): + hour_start = slot.activity_id.hour_start + (slot.activity_id.slots_duration * id_slot) + hour_stop = hour_start + slot.activity_id.slots_duration + slot.write({ + 'hour_start': hour_start, + 'hour_stop': hour_stop + })