Create registration slot

This commit is contained in:
Youssef Elouahby 2018-11-02 11:40:31 +01:00
parent 6916f60f3a
commit 482acded87
1 changed files with 8 additions and 3 deletions

View File

@ -30,11 +30,16 @@ class GolemActivityRegistration(models.Model):
""" Create registration slot """
reg = super(GolemActivityRegistration, self).create(vals)
if reg.activity_id.individual_slots:
slots = self.env['golem.activity.registration.slot'].search([], order='hour_stop')
slots = self.env['golem.activity.registration.slot'].search(
[('activity_id', '=', reg.activity_id.id)], order='hour_stop')
if len(slots) >= reg.activity_id.slots_number:
verr = _(u'No available slot to register in this activity')
raise ValidationError(verr)
hour_start = slots[-1].hour_stop if slots else reg.activity_id.hour_start
self.env['golem.activity.registration.slot'].create({
'activity_id': reg.activity_id.id,
'member_id': reg.member_id.id,
'hour_start': slots[-1].hour_stop,
'hour_stop': slots[-1].hour_stop + reg.activity_id.slots_duration
'hour_start': hour_start,
'hour_stop': hour_start + reg.activity_id.slots_duration
})
return reg