Activités : inscription par créneau interne #41

Open
youssef wants to merge 15 commits from youssef/GOLEM:activites_inscription_par_creneau_interne into master
1 changed files with 16 additions and 0 deletions
Showing only changes of commit ce8a3c0adc - Show all commits

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