diff --git a/golem_activity_registration_slot/models/golem_activity_registration.py b/golem_activity_registration_slot/models/golem_activity_registration.py index 077dc43..12d8bb0 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration.py +++ b/golem_activity_registration_slot/models/golem_activity_registration.py @@ -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