Browse Source

[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.
pull/24/head
Rémy Taymans 7 years ago
committed by Thibault Francois
parent
commit
dcaa986066
  1. 1
      beesdoo_portal_shift/__init__.py
  2. 24
      beesdoo_portal_shift/__openerp__.py
  3. 1
      beesdoo_portal_shift/controllers/__init__.py
  4. 99
      beesdoo_portal_shift/controllers/main.py
  5. 17
      beesdoo_portal_shift/data/config_data.xml
  6. 122
      beesdoo_portal_shift/i18n/fr_BE.po
  7. 3
      beesdoo_portal_shift/static/src/css/design.css
  8. 123
      beesdoo_portal_shift/views/shift_portal_templates.xml

1
beesdoo_portal_shift/__init__.py

@ -0,0 +1 @@
from . import controllers

24
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',
]
}

1
beesdoo_portal_shift/controllers/__init__.py

@ -0,0 +1 @@
from . import main

99
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

17
beesdoo_portal_shift/data/config_data.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="menu_work_irregular" model="website.menu">
<field name="name">Shifts Irregular</field>
<field name="url">/shift_irregular_worker</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">50</field>
</record>
<record id="menu_work_regular" model="website.menu">
<field name="name">Shifts Regular</field>
<field name="url">/shift_template_regular_worker</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">51</field>
</record>
</data>
</openerp>

122
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 <remytaymans@gmail.com>, 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"

3
beesdoo_portal_shift/static/src/css/design.css

@ -0,0 +1,3 @@
h1 {
color: grey;
}

123
beesdoo_portal_shift/views/shift_portal_templates.xml

@ -0,0 +1,123 @@
<openerp>
<!-- We add the css stylesheet -->
<template id="assets_frontend" name="beesdoo_portal_shift_website_assets"
inherit_id="website.assets_frontend">
<xpath expr="." position="inside">
<link rel="stylesheet" type="text/css"
href="/beesdoo_portal_shift/static/src/css/design.css"/>
</xpath>
</template>
<!-- Task template page -->
<template id="task_template" name="Task template for regular worker">
<t t-call="website.layout">
<div class="container">
<h1>Available Tasks Templates for Regular Workers</h1>
<p class="text-center">
Subscribe via the member office or via <a href="mailto:membre@bees-coop.be">membre@bees-coop.be</a>
</p>
<table class="table table-striped">
<thead>
<tr>
<th>Week</th>
<th>Task Template</th>
<th>Day</th>
<th>Time</th>
<th>Type of Task</th>
<th>Super Co-operator</th>
<th class="text-center">Available Spaces</th>
</tr>
</thead>
<tbody>
<t t-foreach="task_templates" t-as="template">
<!-- Row with no super coop will be shown in color -->
<tr t-attf-class="{{ 'warning' if not template.super_coop_id else '' }}">
<td>
<t t-esc="template.planning_id.name"/>
</td>
<td>
<t t-esc="template.name"/>
</td>
<td>
<t t-esc="template.day_nb_id.name"/>
</td>
<td>
<t t-esc='task_template_times[template_index]["start_hour"]'/>:<t t-esc='task_template_times[template_index]["start_minute"]'/> -
<t t-esc='task_template_times[template_index]["end_hour"]'/>:<t t-esc='task_template_times[template_index]["end_minute"]'/>
</td>
<td>
<t t-esc="template.task_type_id.name"/>
</td>
<td>
<t t-if="template.super_coop_id">
Yes
</t>
<t t-if="not template.super_coop_id">
Not yet
</t>
</td>
<td class="text-center">
<t t-esc="template.remaining_worker"/>
</td>
</tr>
</t>
</tbody>
</table>
</div>
</t>
</template>
<!-- Shift page -->
<template id="shift_template" name="Shift for irregular worker">
<t t-call="website.layout">
<div class="container">
<h1>Availables Shifts for Irregular Workers</h1>
<p class="text-center">
Subscribe via <a href="mailto:volant@bees-coop.be">volant@bees-coop.be</a>
</p>
<table class="table table-striped">
<thead>
<tr>
<th>Day</th>
<th>Date</th>
<th>Time</th>
<th>Shift</th>
<th>Type of Shift</th>
<th class="text-center">Available Spaces</th>
</tr>
</thead>
<tbody>
<t t-foreach="shift_templates" t-as="shift">
<tr>
<td>
<t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
</td>
<td>
<t t-esc="time.strftime('%d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
</td>
<td>
<span t-field="shift.shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
<span t-field="shift.shift.end_time" t-field-options='{"format": "HH:mm"}'/>
</td>
<td>
<t t-esc="shift.name"/>
</td>
<td>
<t t-esc="shift.task_type"/>
</td>
<td class="text-center">
<t t-esc="shift.remaining_space"/>
</td>
</tr>
</t>
</tbody>
</table>
</div>
</t>
</template>
</openerp>
Loading…
Cancel
Save