From 8008533e73f9b683dbcce4fdb3a64e6735d78502 Mon Sep 17 00:00:00 2001 From: youssef Date: Thu, 1 Nov 2018 02:13:36 +0100 Subject: [PATCH 01/15] Create __manifest__ --- .../__manifest__.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 golem_activity_registration_slot/__manifest__.py 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'] +} -- 2.40.1 From e8f60a8f97670b825716a93420f314fc5f0ad799 Mon Sep 17 00:00:00 2001 From: youssef Date: Thu, 1 Nov 2018 02:14:25 +0100 Subject: [PATCH 02/15] Create __init__ --- golem_activity_registration_slot/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 golem_activity_registration_slot/__init__.py 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 -- 2.40.1 From 6e11886259f9fe81f8bd400173e61dc3ad1d698b Mon Sep 17 00:00:00 2001 From: youssef Date: Thu, 1 Nov 2018 02:16:57 +0100 Subject: [PATCH 03/15] Extend golem_activity_form to add registration_slot --- .../views/golem_activity_views.xml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 golem_activity_registration_slot/views/golem_activity_views.xml 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..84d7542 --- /dev/null +++ b/golem_activity_registration_slot/views/golem_activity_views.xml @@ -0,0 +1,50 @@ + + + + + + + + Add registration slot to activity form + golem.activity + + + + + + + + + + + + + + + + + + + + + + + -- 2.40.1 From 90e6f85235a5cf7d152f34b57cf0f6c1668d60ba Mon Sep 17 00:00:00 2001 From: youssef Date: Thu, 1 Nov 2018 02:17:43 +0100 Subject: [PATCH 04/15] Inherit golem_activity model to add registration_slot --- .../models/golem_activity.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 golem_activity_registration_slot/models/golem_activity.py 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..31dce94 --- /dev/null +++ b/golem_activity_registration_slot/models/golem_activity.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 . + +""" 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') -- 2.40.1 From 71418d5d85714cd803d37c87147df3578e58828a Mon Sep 17 00:00:00 2001 From: youssef Date: Thu, 1 Nov 2018 02:18:34 +0100 Subject: [PATCH 05/15] Create golem_activity_registration_slot model --- .../golem_activity_registration_slot.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 golem_activity_registration_slot/models/golem_activity_registration_slot.py 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..2df895d --- /dev/null +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.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 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' + + _description = 'GOLEM Activity Registration Slot' + activity_id = fields.Many2one('golem.activity', required=True, + string='Activity', ondelete='cascade', + index=True) + hour_start = fields.Float('Start time') + hour_stop = fields.Float('Stop time') -- 2.40.1 From 5f14d6ca777fc71367ad0c0f2f2e1ac891de136a Mon Sep 17 00:00:00 2001 From: youssef Date: Thu, 1 Nov 2018 02:18:58 +0100 Subject: [PATCH 06/15] Create models/__init__ --- .../models/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 golem_activity_registration_slot/models/__init__.py diff --git a/golem_activity_registration_slot/models/__init__.py b/golem_activity_registration_slot/models/__init__.py new file mode 100644 index 0000000..c9fb9ef --- /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 -- 2.40.1 From 231aa1c07ea4e0672aa378d0451583595a2b44b7 Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 01:59:52 +0100 Subject: [PATCH 07/15] Create registration_slot when a registration is created --- .../models/golem_activity_registration.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 golem_activity_registration_slot/models/golem_activity_registration.py 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..077dc43 --- /dev/null +++ b/golem_activity_registration_slot/models/golem_activity_registration.py @@ -0,0 +1,40 @@ +# -*- 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([], order='hour_stop') + 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 + }) + return reg -- 2.40.1 From f4bfa8afe9fe986631fef543d629211120ebbfb7 Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 02:00:33 +0100 Subject: [PATCH 08/15] Add member_id to registration_slot --- .../models/golem_activity_registration_slot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/golem_activity_registration_slot/models/golem_activity_registration_slot.py b/golem_activity_registration_slot/models/golem_activity_registration_slot.py index 2df895d..183a539 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration_slot.py +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -29,5 +29,7 @@ class GolemActivityRegistrationSlot(models.Model): 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') -- 2.40.1 From 8ceb95f3f3131bc82337c630c2a08bd334019e43 Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 02:00:57 +0100 Subject: [PATCH 09/15] small refactorings --- golem_activity_registration_slot/models/__init__.py | 2 +- golem_activity_registration_slot/models/golem_activity.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/golem_activity_registration_slot/models/__init__.py b/golem_activity_registration_slot/models/__init__.py index c9fb9ef..68b4abb 100644 --- a/golem_activity_registration_slot/models/__init__.py +++ b/golem_activity_registration_slot/models/__init__.py @@ -16,4 +16,4 @@ # 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 +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 index 31dce94..c988bb6 100644 --- a/golem_activity_registration_slot/models/golem_activity.py +++ b/golem_activity_registration_slot/models/golem_activity.py @@ -29,3 +29,5 @@ class GolemActivity(models.Model): 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') -- 2.40.1 From 288dc1805635b6df3cd9e238ef0e32714fb629f4 Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 02:01:11 +0100 Subject: [PATCH 10/15] small refactorings --- golem_activity_registration_slot/views/golem_activity_views.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/golem_activity_registration_slot/views/golem_activity_views.xml b/golem_activity_registration_slot/views/golem_activity_views.xml index 84d7542..b1cca09 100644 --- a/golem_activity_registration_slot/views/golem_activity_views.xml +++ b/golem_activity_registration_slot/views/golem_activity_views.xml @@ -37,6 +37,7 @@ along with this program. If not, see . + -- 2.40.1 From 42cec4f0e1c8480eaa2d45d38f6c2f77734186de Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 11:37:16 +0100 Subject: [PATCH 11/15] check slot hours consistence --- .../models/golem_activity_registration_slot.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/golem_activity_registration_slot/models/golem_activity_registration_slot.py b/golem_activity_registration_slot/models/golem_activity_registration_slot.py index 183a539..332772f 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration_slot.py +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -33,3 +33,13 @@ class GolemActivityRegistrationSlot(models.Model): ondelete='cascade', index=True) hour_start = fields.Float('Start time') hour_stop = fields.Float('Stop time') + + @api.constrains('hour_start', 'hour_stop') + def check_slot_hours(self): + """ Check slot hours consistence """ + for slot in self: + 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) -- 2.40.1 From 6916f60f3add1de311361b51797e8416888b9a4f Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 11:40:10 +0100 Subject: [PATCH 12/15] Create registration slot when a slot is available --- .../models/golem_activity_registration_slot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golem_activity_registration_slot/models/golem_activity_registration_slot.py b/golem_activity_registration_slot/models/golem_activity_registration_slot.py index 332772f..79ba11f 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration_slot.py +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -36,7 +36,7 @@ class GolemActivityRegistrationSlot(models.Model): @api.constrains('hour_start', 'hour_stop') def check_slot_hours(self): - """ Check slot hours consistence """ + """ Check slot hours consistency """ for slot in self: if slot.hour_start < slot.activity_id.hour_start or \ slot.hour_stop > slot.activity_id.hour_stop: -- 2.40.1 From 482acded87e9bac41cc923de65139195e4e580ab Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 11:40:31 +0100 Subject: [PATCH 13/15] Create registration slot --- .../models/golem_activity_registration.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 -- 2.40.1 From cc7ac213951d831e76bc967d3935528da1d2d2b4 Mon Sep 17 00:00:00 2001 From: youssef Date: Fri, 2 Nov 2018 11:52:34 +0100 Subject: [PATCH 14/15] Add sequence ordering --- .../models/golem_activity_registration_slot.py | 2 ++ golem_activity_registration_slot/views/golem_activity_views.xml | 1 + 2 files changed, 3 insertions(+) diff --git a/golem_activity_registration_slot/models/golem_activity_registration_slot.py b/golem_activity_registration_slot/models/golem_activity_registration_slot.py index 79ba11f..f02d0d6 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration_slot.py +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -24,6 +24,7 @@ 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, @@ -33,6 +34,7 @@ class GolemActivityRegistrationSlot(models.Model): 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): diff --git a/golem_activity_registration_slot/views/golem_activity_views.xml b/golem_activity_registration_slot/views/golem_activity_views.xml index b1cca09..a5af9d4 100644 --- a/golem_activity_registration_slot/views/golem_activity_views.xml +++ b/golem_activity_registration_slot/views/golem_activity_views.xml @@ -37,6 +37,7 @@ along with this program. If not, see . + -- 2.40.1 From ce8a3c0adc0a23f22ff510e63f60e3aeeacff708 Mon Sep 17 00:00:00 2001 From: youssef Date: Sun, 4 Nov 2018 00:53:30 +0100 Subject: [PATCH 15/15] Calculate slots hours after slots reordering --- .../models/golem_activity_registration_slot.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/golem_activity_registration_slot/models/golem_activity_registration_slot.py b/golem_activity_registration_slot/models/golem_activity_registration_slot.py index f02d0d6..9683f65 100644 --- a/golem_activity_registration_slot/models/golem_activity_registration_slot.py +++ b/golem_activity_registration_slot/models/golem_activity_registration_slot.py @@ -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 + }) -- 2.40.1