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] [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 @@ + + + + + + + + + +