From dcaa9860665c7584d02f829fb8f793c1a10604e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Tue, 26 Sep 2017 15:42:45 +0200 Subject: [PATCH 1/3] [ADD] Page that show remaining space in shifts [FIX] Allow access for unsigned user [ADD] Add page that shows space for regular worker [IMP] Page that shows space for regular worker [ADD] Button in top menu [IMP] Translation for button in menu [IMP] Module description [FIX] beesdoo_portal_shift: Access rights [IMP] beesdoo_portal_shift: Add day name in report [FIX] beesdoo_portal_shift: Typo controller name [FIX] beesdoo_portal_shift: Trans "Task Template" [FIX] beesdoo_portal_shift: Change access process The access to beesdoo_shift models was given by an ir.model.access. This is not secure as it give access to all users to the shifts. We prefere using sudo() in the controllers that are conserned. --- beesdoo_portal_shift/__init__.py | 1 + beesdoo_portal_shift/__openerp__.py | 24 ++++ beesdoo_portal_shift/controllers/__init__.py | 1 + beesdoo_portal_shift/controllers/main.py | 99 ++++++++++++++ beesdoo_portal_shift/data/config_data.xml | 17 +++ beesdoo_portal_shift/i18n/fr_BE.po | 122 +++++++++++++++++ .../static/src/css/design.css | 3 + .../views/shift_portal_templates.xml | 123 ++++++++++++++++++ 8 files changed, 390 insertions(+) create mode 100644 beesdoo_portal_shift/__init__.py create mode 100644 beesdoo_portal_shift/__openerp__.py create mode 100644 beesdoo_portal_shift/controllers/__init__.py create mode 100644 beesdoo_portal_shift/controllers/main.py create mode 100644 beesdoo_portal_shift/data/config_data.xml create mode 100644 beesdoo_portal_shift/i18n/fr_BE.po create mode 100644 beesdoo_portal_shift/static/src/css/design.css create mode 100644 beesdoo_portal_shift/views/shift_portal_templates.xml diff --git a/beesdoo_portal_shift/__init__.py b/beesdoo_portal_shift/__init__.py new file mode 100644 index 0000000..e046e49 --- /dev/null +++ b/beesdoo_portal_shift/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/beesdoo_portal_shift/__openerp__.py b/beesdoo_portal_shift/__openerp__.py new file mode 100644 index 0000000..b0376b0 --- /dev/null +++ b/beesdoo_portal_shift/__openerp__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Beescoop Shift Portal', + + 'summary': """ + Show available shifts for regular and irregular workers in + portal. + """, + 'description': """ + """, + + 'author': 'Rémy Taymans', + 'website': "https://github.com/beescoop/Obeesdoo", + + 'category': 'Cooperative management', + 'version': '0.1', + + 'depends': ['website', 'beesdoo_shift'], + + 'data': [ + 'views/shift_portal_templates.xml', + 'data/config_data.xml', + ] +} diff --git a/beesdoo_portal_shift/controllers/__init__.py b/beesdoo_portal_shift/controllers/__init__.py new file mode 100644 index 0000000..12a7e52 --- /dev/null +++ b/beesdoo_portal_shift/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/beesdoo_portal_shift/controllers/main.py b/beesdoo_portal_shift/controllers/main.py new file mode 100644 index 0000000..d5b1538 --- /dev/null +++ b/beesdoo_portal_shift/controllers/main.py @@ -0,0 +1,99 @@ +# -*- coding: utf8 -*- +from datetime import datetime +from math import floor + +from openerp import http +from openerp.http import request + +class ShiftPortalController(http.Controller): + + @http.route('/shift_irregular_worker', auth='public', website=True) + def shift_irregular_worker(self, **kwargs): + # Get all the shifts in the future with no worker + now = datetime.now() + shifts = request.env['beesdoo.shift.shift'].sudo().search( + [('start_time', '>', now.strftime("%Y-%m-%d %H:%M:%S")), + ('worker_id', '=', False)], + order="start_time, task_template_id, task_type_id", + ) + # Loop on all the shifts + shift_templates = [] + current_template = None + current_shift_template = None + current_remaining_space = 0 + for shift in shifts: + # For a planning id, count the number of shift that don't + # have a worker. + if shift.task_template_id == current_template: + # If we are in the same template then update the number + # of available sapce + current_remaining_space = current_remaining_space + 1 + else: + if current_shift_template: + # Save the old current_shift_template + current_shift_template.remaining_space = current_remaining_space + shift_templates.append(current_shift_template) + + # Initiate the new current_shift_template + current_template = shift.task_template_id + current_remaining_space = 1 + current_shift_template = ShiftTemplate(shift, + shift.start_time, + shift.end_time, + current_template.name, + current_template.task_type_id.name) + + return request.render( + 'beesdoo_portal_shift.shift_template', + {'shift_templates': shift_templates} + ) + + @http.route('/shift_template_regular_worker', auth='public', website=True) + def shift_template_regular_worker(self, **kwargs): + # Get all the task template + task_templates = request.env['beesdoo.shift.template'].sudo().search( + [], + order="planning_id, day_nb_id, start_time", + ) + + # Compute start_time and end_time + task_template_times = [] + cur_start_hour = 0 + cur_start_minute = 0 + cur_end_hour = 0 + cur_end_minute = 0 + for template in task_templates: + cur_start_hour = floor(template.start_time) + cur_start_minute = floor((template.start_time - + cur_start_hour) * 60) + cur_end_hour = floor(template.end_time) + cur_end_minute = floor((template.end_time - + cur_end_hour) * 60) + task_template_times.append( + {"start_hour": "%02d" % cur_start_hour, + "start_minute": "%02d" % cur_start_minute, + "end_hour": "%02d" % cur_end_hour, + "end_minute": "%02d" % cur_end_minute} + ) + + return request.render( + 'beesdoo_portal_shift.task_template', + {'task_templates': task_templates, + 'task_template_times': task_template_times} + ) + + +class ShiftTemplate(object): + shift = None + start_time = None + end_time = None + name = '' + task_type = '' + remaining_space = 0 + + def __init__(self, shift, start_time, end_time, name, task_type): + self.shift = shift + self.start_time = start_time + self.end_time = end_time + self.name = name + self.task_type = task_type diff --git a/beesdoo_portal_shift/data/config_data.xml b/beesdoo_portal_shift/data/config_data.xml new file mode 100644 index 0000000..f028307 --- /dev/null +++ b/beesdoo_portal_shift/data/config_data.xml @@ -0,0 +1,17 @@ + + + + + Shifts Irregular + /shift_irregular_worker + + 50 + + + Shifts Regular + /shift_template_regular_worker + + 51 + + + diff --git a/beesdoo_portal_shift/i18n/fr_BE.po b/beesdoo_portal_shift/i18n/fr_BE.po new file mode 100644 index 0000000..7703421 --- /dev/null +++ b/beesdoo_portal_shift/i18n/fr_BE.po @@ -0,0 +1,122 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * beesdoo_portal_shift +# +# Tanslators: +# Rémy Taymans , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-09-29 09:02+0000\n" +"PO-Revision-Date: 2017-09-29 11:08+0200\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: fr_BE\n" +"X-Generator: Poedit 1.8.11\n" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Available Tasks Templates for Regular Workers" +msgstr "Créneaux disponibles pour les travailleurs réguliers" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +msgid "Availables Shifts for Irregular Workers" +msgstr "Shifts disponibles pour les travailleurs volants" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +msgid "Date" +msgstr "Date" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +msgid "Day" +msgstr "Jour" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Available Spaces" +msgstr "Places disponibles" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Subscribe via the member office or via" +msgstr "Inscription au bureau des membres ou via" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +msgid "Subscribe via" +msgstr "Inscription via" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Not yet" +msgstr "Pas encore" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +msgid "Shift" +msgstr "Shift" + +#. module: beesdoo_portal_shift +#: model:website.menu,name:beesdoo_portal_shift.menu_work_irregular +msgid "Shifts Irregular" +msgstr "Shifts" + +#. module: beesdoo_portal_shift +#: model:website.menu,name:beesdoo_portal_shift.menu_work_regular +msgid "Shifts Regular" +msgstr "Créneaux" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Super Co-operator" +msgstr "Super-coopérateur" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Task Template" +msgstr "Créneau" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Time" +msgstr "Heures" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +msgid "Type of Shift" +msgstr "Type de shift" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Type of Task" +msgstr "Type de créneau" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Week" +msgstr "Semaine" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "Yes" +msgstr "Oui" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.task_template +msgid "membre@bees-coop.be" +msgstr "membre@bees-coop.be" + +#. module: beesdoo_portal_shift +#: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template +msgid "volant@bees-coop.be" +msgstr "volant@bees-coop.be" diff --git a/beesdoo_portal_shift/static/src/css/design.css b/beesdoo_portal_shift/static/src/css/design.css new file mode 100644 index 0000000..acfb05a --- /dev/null +++ b/beesdoo_portal_shift/static/src/css/design.css @@ -0,0 +1,3 @@ +h1 { + color: grey; +} diff --git a/beesdoo_portal_shift/views/shift_portal_templates.xml b/beesdoo_portal_shift/views/shift_portal_templates.xml new file mode 100644 index 0000000..00dcbec --- /dev/null +++ b/beesdoo_portal_shift/views/shift_portal_templates.xml @@ -0,0 +1,123 @@ + + + + + + + + + + From dcac5953e2012e380beae9243ec1eb9199da7903 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 12 Oct 2017 22:27:28 +0200 Subject: [PATCH 2/3] [REVIEW] Make the code much simplier, use groupby for irregular worker and use float_to_time for regular worker --- beesdoo_portal_shift/controllers/main.py | 94 ++++--------------- .../views/shift_portal_templates.xml | 18 ++-- 2 files changed, 28 insertions(+), 84 deletions(-) diff --git a/beesdoo_portal_shift/controllers/main.py b/beesdoo_portal_shift/controllers/main.py index d5b1538..501a583 100644 --- a/beesdoo_portal_shift/controllers/main.py +++ b/beesdoo_portal_shift/controllers/main.py @@ -1,10 +1,11 @@ # -*- coding: utf8 -*- from datetime import datetime -from math import floor - +from itertools import groupby from openerp import http from openerp.http import request +from openerp.addons.beesdoo_shift.models.planning import float_to_time + class ShiftPortalController(http.Controller): @http.route('/shift_irregular_worker', auth='public', website=True) @@ -16,84 +17,25 @@ class ShiftPortalController(http.Controller): ('worker_id', '=', False)], order="start_time, task_template_id, task_type_id", ) - # Loop on all the shifts - shift_templates = [] - current_template = None - current_shift_template = None - current_remaining_space = 0 - for shift in shifts: - # For a planning id, count the number of shift that don't - # have a worker. - if shift.task_template_id == current_template: - # If we are in the same template then update the number - # of available sapce - current_remaining_space = current_remaining_space + 1 - else: - if current_shift_template: - # Save the old current_shift_template - current_shift_template.remaining_space = current_remaining_space - shift_templates.append(current_shift_template) - # Initiate the new current_shift_template - current_template = shift.task_template_id - current_remaining_space = 1 - current_shift_template = ShiftTemplate(shift, - shift.start_time, - shift.end_time, - current_template.name, - current_template.task_type_id.name) + shifts_and_count = [] + for _, val in groupby(shifts, lambda s: s.task_template_id): + s = [v for v in val] + shifts_and_count.append([len(s), s[0]]) - return request.render( - 'beesdoo_portal_shift.shift_template', - {'shift_templates': shift_templates} + return request.render('beesdoo_portal_shift.shift_template', + {'shift_templates': shifts_and_count} ) @http.route('/shift_template_regular_worker', auth='public', website=True) def shift_template_regular_worker(self, **kwargs): # Get all the task template - task_templates = request.env['beesdoo.shift.template'].sudo().search( - [], - order="planning_id, day_nb_id, start_time", - ) - - # Compute start_time and end_time - task_template_times = [] - cur_start_hour = 0 - cur_start_minute = 0 - cur_end_hour = 0 - cur_end_minute = 0 - for template in task_templates: - cur_start_hour = floor(template.start_time) - cur_start_minute = floor((template.start_time - - cur_start_hour) * 60) - cur_end_hour = floor(template.end_time) - cur_end_minute = floor((template.end_time - - cur_end_hour) * 60) - task_template_times.append( - {"start_hour": "%02d" % cur_start_hour, - "start_minute": "%02d" % cur_start_minute, - "end_hour": "%02d" % cur_end_hour, - "end_minute": "%02d" % cur_end_minute} - ) - - return request.render( - 'beesdoo_portal_shift.task_template', - {'task_templates': task_templates, - 'task_template_times': task_template_times} - ) - - -class ShiftTemplate(object): - shift = None - start_time = None - end_time = None - name = '' - task_type = '' - remaining_space = 0 - - def __init__(self, shift, start_time, end_time, name, task_type): - self.shift = shift - self.start_time = start_time - self.end_time = end_time - self.name = name - self.task_type = task_type + template = request.env['beesdoo.shift.template'] + task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time") + + return request.render('beesdoo_portal_shift.task_template', + { + 'task_templates': task_templates, + 'float_to_time': float_to_time + } + ) \ No newline at end of file diff --git a/beesdoo_portal_shift/views/shift_portal_templates.xml b/beesdoo_portal_shift/views/shift_portal_templates.xml index 00dcbec..6e12fcb 100644 --- a/beesdoo_portal_shift/views/shift_portal_templates.xml +++ b/beesdoo_portal_shift/views/shift_portal_templates.xml @@ -44,8 +44,8 @@ - : - - : + - + @@ -92,7 +92,9 @@ - + + + @@ -101,17 +103,17 @@ - - - + - + - + - + - + From 8979cf2a4366f6df03faf9a8bca5e71edfb2d2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Fri, 13 Oct 2017 11:57:24 +0200 Subject: [PATCH 3/3] [FIX] beesdoo_portal_shift: change name Change name from beesdoo_portal_shift to beesdoo_website_shift. --- {beesdoo_portal_shift => beesdoo_website_shift}/__init__.py | 0 .../__openerp__.py | 4 ++-- .../controllers/__init__.py | 0 .../controllers/main.py | 4 ++-- .../data/config_data.xml | 0 .../i18n/fr_BE.po | 2 +- .../static/src/css/design.css | 0 .../views/shift_website_templates.xml | 6 +++--- 8 files changed, 8 insertions(+), 8 deletions(-) rename {beesdoo_portal_shift => beesdoo_website_shift}/__init__.py (100%) rename {beesdoo_portal_shift => beesdoo_website_shift}/__openerp__.py (83%) rename {beesdoo_portal_shift => beesdoo_website_shift}/controllers/__init__.py (100%) rename {beesdoo_portal_shift => beesdoo_website_shift}/controllers/main.py (90%) rename {beesdoo_portal_shift => beesdoo_website_shift}/data/config_data.xml (100%) rename {beesdoo_portal_shift => beesdoo_website_shift}/i18n/fr_BE.po (98%) rename {beesdoo_portal_shift => beesdoo_website_shift}/static/src/css/design.css (100%) rename beesdoo_portal_shift/views/shift_portal_templates.xml => beesdoo_website_shift/views/shift_website_templates.xml (95%) diff --git a/beesdoo_portal_shift/__init__.py b/beesdoo_website_shift/__init__.py similarity index 100% rename from beesdoo_portal_shift/__init__.py rename to beesdoo_website_shift/__init__.py diff --git a/beesdoo_portal_shift/__openerp__.py b/beesdoo_website_shift/__openerp__.py similarity index 83% rename from beesdoo_portal_shift/__openerp__.py rename to beesdoo_website_shift/__openerp__.py index b0376b0..ea05970 100644 --- a/beesdoo_portal_shift/__openerp__.py +++ b/beesdoo_website_shift/__openerp__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- { - 'name': 'Beescoop Shift Portal', + 'name': 'Beescoop Shift Website', 'summary': """ Show available shifts for regular and irregular workers in @@ -18,7 +18,7 @@ 'depends': ['website', 'beesdoo_shift'], 'data': [ - 'views/shift_portal_templates.xml', + 'views/shift_website_templates.xml', 'data/config_data.xml', ] } diff --git a/beesdoo_portal_shift/controllers/__init__.py b/beesdoo_website_shift/controllers/__init__.py similarity index 100% rename from beesdoo_portal_shift/controllers/__init__.py rename to beesdoo_website_shift/controllers/__init__.py diff --git a/beesdoo_portal_shift/controllers/main.py b/beesdoo_website_shift/controllers/main.py similarity index 90% rename from beesdoo_portal_shift/controllers/main.py rename to beesdoo_website_shift/controllers/main.py index 501a583..14f205a 100644 --- a/beesdoo_portal_shift/controllers/main.py +++ b/beesdoo_website_shift/controllers/main.py @@ -23,7 +23,7 @@ class ShiftPortalController(http.Controller): s = [v for v in val] shifts_and_count.append([len(s), s[0]]) - return request.render('beesdoo_portal_shift.shift_template', + return request.render('beesdoo_website_shift.shift_template', {'shift_templates': shifts_and_count} ) @@ -33,7 +33,7 @@ class ShiftPortalController(http.Controller): template = request.env['beesdoo.shift.template'] task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time") - return request.render('beesdoo_portal_shift.task_template', + return request.render('beesdoo_website_shift.task_template', { 'task_templates': task_templates, 'float_to_time': float_to_time diff --git a/beesdoo_portal_shift/data/config_data.xml b/beesdoo_website_shift/data/config_data.xml similarity index 100% rename from beesdoo_portal_shift/data/config_data.xml rename to beesdoo_website_shift/data/config_data.xml diff --git a/beesdoo_portal_shift/i18n/fr_BE.po b/beesdoo_website_shift/i18n/fr_BE.po similarity index 98% rename from beesdoo_portal_shift/i18n/fr_BE.po rename to beesdoo_website_shift/i18n/fr_BE.po index 7703421..605ffd5 100644 --- a/beesdoo_portal_shift/i18n/fr_BE.po +++ b/beesdoo_website_shift/i18n/fr_BE.po @@ -26,7 +26,7 @@ msgstr "Créneaux disponibles pour les travailleurs réguliers" #. module: beesdoo_portal_shift #: model:ir.ui.view,arch_db:beesdoo_portal_shift.shift_template -msgid "Availables Shifts for Irregular Workers" +msgid "Available Shifts for Irregular Workers" msgstr "Shifts disponibles pour les travailleurs volants" #. module: beesdoo_portal_shift diff --git a/beesdoo_portal_shift/static/src/css/design.css b/beesdoo_website_shift/static/src/css/design.css similarity index 100% rename from beesdoo_portal_shift/static/src/css/design.css rename to beesdoo_website_shift/static/src/css/design.css diff --git a/beesdoo_portal_shift/views/shift_portal_templates.xml b/beesdoo_website_shift/views/shift_website_templates.xml similarity index 95% rename from beesdoo_portal_shift/views/shift_portal_templates.xml rename to beesdoo_website_shift/views/shift_website_templates.xml index 6e12fcb..8a00e24 100644 --- a/beesdoo_portal_shift/views/shift_portal_templates.xml +++ b/beesdoo_website_shift/views/shift_website_templates.xml @@ -1,10 +1,10 @@ - @@ -74,7 +74,7 @@