diff --git a/golem_activity_registration_slot/__init__.py b/golem_activity_registration_slot/__init__.py new file mode 100644 index 0000000..1fced20 --- /dev/null +++ b/golem_activity_registration_slot/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import models diff --git a/golem_activity_registration_slot/__manifest__.py b/golem_activity_registration_slot/__manifest__.py new file mode 100644 index 0000000..3f096f8 --- /dev/null +++ b/golem_activity_registration_slot/__manifest__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +{ + 'name': 'GOLEM activity registration slot', + 'summary': 'GOLEM activity registration slot', + 'description': ''' GOLEM activity registration slot management ''', + 'version': '10.0.0.0.1', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_activity_registration'], + 'data': ['views/golem_activity_views.xml'] +} diff --git a/golem_activity_registration_slot/models/__init__.py b/golem_activity_registration_slot/models/__init__.py new file mode 100644 index 0000000..68b4abb --- /dev/null +++ b/golem_activity_registration_slot/models/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import golem_activity, golem_activity_registration_slot, golem_activity_registration diff --git a/golem_activity_registration_slot/models/golem_activity.py b/golem_activity_registration_slot/models/golem_activity.py new file mode 100644 index 0000000..c988bb6 --- /dev/null +++ b/golem_activity_registration_slot/models/golem_activity.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" GOLEM Activity adaptations """ + +from odoo import models, fields, api, _ + +class GolemActivity(models.Model): + """ GOLEM Activity adaptations """ + _inherit = 'golem.activity' + + individual_slots = fields.Boolean(string='Individual slots activity') + slots_number = fields.Integer(string='Registration Slot Number') + slots_duration = fields.Float(string='Registration Slot Duration') + registration_slot_ids = fields.One2many('golem.activity.registration.slot', 'activity_id', + string='Registration Slots') + + #@api.constrains('slots_number', 'slots_duration') diff --git a/golem_activity_registration_slot/models/golem_activity_registration.py b/golem_activity_registration_slot/models/golem_activity_registration.py new file mode 100644 index 0000000..12d8bb0 --- /dev/null +++ b/golem_activity_registration_slot/models/golem_activity_registration.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" GOLEM Activity Registration """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + +class GolemActivityRegistration(models.Model): + """ GOLEM Activity Registration Adaptations""" + _inherit = 'golem.activity.registration' + + @api.model + def create(self, vals): + """ Create registration slot """ + reg = super(GolemActivityRegistration, self).create(vals) + if reg.activity_id.individual_slots: + 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': hour_start, + 'hour_stop': hour_start + reg.activity_id.slots_duration + }) + return reg diff --git a/golem_activity_registration_slot/models/golem_activity_registration_slot.py b/golem_activity_registration_slot/models/golem_activity_registration_slot.py new file mode 100644 index 0000000..9683f65 --- /dev/null +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" GOLEM Activity Registration Slot """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + +class GolemActivityRegistrationSlot(models.Model): + """ GOLEM Activity Registration Slot """ + _name = 'golem.activity.registration.slot' + _order = 'sequence' + + _description = 'GOLEM Activity Registration Slot' + activity_id = fields.Many2one('golem.activity', required=True, + string='Activity', ondelete='cascade', + index=True) + member_id = fields.Many2one('golem.member', string='Member', + ondelete='cascade', index=True) + hour_start = fields.Float('Start time') + hour_stop = fields.Float('Stop time') + sequence = fields.Integer('Sequence') + + @api.constrains('hour_start', 'hour_stop') + 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 + }) diff --git a/golem_activity_registration_slot/views/golem_activity_views.xml b/golem_activity_registration_slot/views/golem_activity_views.xml new file mode 100644 index 0000000..a5af9d4 --- /dev/null +++ b/golem_activity_registration_slot/views/golem_activity_views.xml @@ -0,0 +1,52 @@ + + + + + + + + Add registration slot to activity form + golem.activity + + + + + + + + + + + + + + + + + + + + + + + + +