Calculate slots hours after slots reordering

This commit is contained in:
Youssef Elouahby 2018-11-04 00:53:30 +01:00
parent cc7ac21395
commit ce8a3c0adc
1 changed files with 16 additions and 0 deletions

View File

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