forked from Yaltik/golem
Calculate slots hours after slots reordering
This commit is contained in:
parent
cc7ac21395
commit
ce8a3c0adc
@ -40,8 +40,24 @@ class GolemActivityRegistrationSlot(models.Model):
|
|||||||
def check_slot_hours(self):
|
def check_slot_hours(self):
|
||||||
""" Check slot hours consistency """
|
""" Check slot hours consistency """
|
||||||
for slot in self:
|
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 \
|
if slot.hour_start < slot.activity_id.hour_start or \
|
||||||
slot.hour_stop > slot.activity_id.hour_stop:
|
slot.hour_stop > slot.activity_id.hour_stop:
|
||||||
verr = _(u'Slot start and stop must be between activity start and'
|
verr = _(u'Slot start and stop must be between activity start and'
|
||||||
' activity stop.')
|
' activity stop.')
|
||||||
raise ValidationError(verr)
|
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
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user