Browse Source

[IMP] website_shift: Move menu in template

The menu entry was recorded in data folder. But this folder is reserved
for buisness data. So I moved the menu entry in the views directory.

[IMP] website_shift: Responsive design

[IMP] website_shift: change rules of display

Shows only available space:
    if more than 5 max worker and at least two available spaces
    if less than 5 max worker and at least one available spaces

This take care of the case where no task_template is defined in the task

[IMP] website_shift: Make template CMS compliant
pull/128/head
Rémy Taymans 7 years ago
parent
commit
80b00d3bd2
  1. 1
      beesdoo_website_shift/__openerp__.py
  2. 44
      beesdoo_website_shift/controllers/main.py
  3. 17
      beesdoo_website_shift/data/config_data.xml
  4. 330
      beesdoo_website_shift/views/shift_website_templates.xml

1
beesdoo_website_shift/__openerp__.py

@ -19,6 +19,5 @@
'data': [
'views/shift_website_templates.xml',
'data/config_data.xml',
]
}

44
beesdoo_website_shift/controllers/main.py

@ -14,28 +14,50 @@ class ShiftPortalController(http.Controller):
now = datetime.now()
shifts = request.env['beesdoo.shift.shift'].sudo().search(
[('start_time', '>', now.strftime("%Y-%m-%d %H:%M:%S")),
('worker_id', '=', False)],
('worker_id', '=', False)],
order="start_time, task_template_id, task_type_id",
)
# Grouby task_template_id, if no task_template_id is specified
# then group by start_time
groupby_func = lambda s: (s.task_template_id,
s.start_time,
s.task_type_id)
groupby_iter = groupby(shifts, groupby_func)
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]])
for (keys, grouped_shifts) in groupby_iter:
(task_template, start_time, task_type) = keys
s = list(grouped_shifts)
free_space = len(s)
# Among shifts with at least 5 worker max, shows only shifts
# where there is at least two free spaces
if task_template.worker_nb > 5 and len(s) >= 2:
shifts_and_count.append([free_space, s[0]])
# Show available shifts if there is less than 5 worker max
if task_template.worker_nb <= 5:
shifts_and_count.append([free_space, s[0]])
return request.render('beesdoo_website_shift.shift_template',
{'shift_templates': shifts_and_count}
return request.render(
'beesdoo_website_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
template = request.env['beesdoo.shift.template']
task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time")
task_templates = template.sudo().search(
[],
order="planning_id, day_nb_id, start_time"
)
return request.render('beesdoo_website_shift.task_template',
return request.render(
'beesdoo_website_shift.task_template',
{
'task_templates': task_templates,
'float_to_time': float_to_time
'task_templates': task_templates,
'float_to_time': float_to_time
}
)
)

17
beesdoo_website_shift/data/config_data.xml

@ -1,17 +0,0 @@
<?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>

330
beesdoo_website_shift/views/shift_website_templates.xml

@ -1,5 +1,22 @@
<openerp>
<!-- We add the css stylesheet -->
<!-- Add menu entries -->
<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>
<!-- Add the css stylesheet -->
<template id="assets_frontend" name="beesdoo_website_shift_website_assets"
inherit_id="website.assets_frontend">
<xpath expr="." position="inside">
@ -8,118 +25,233 @@
</xpath>
</template>
<!-- Task template page -->
<template id="task_template" name="Task template for regular worker">
<!-- Available Tasks Templates for Regular Workers -->
<template
id="task_template"
name="Available Tasks Templates for Regular Workers"
page="True">
<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>
<div class="oe_structure"/>
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">
Available Tasks Templates for Regular Workers
</h1>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<p class="text-center">
Subscribe via the member office or via
<a href="mailto:volant@bees-coop.be">volant@bees-coop.be</a>
</p>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<section class="wrap">
<div class="container">
<div class="row">
<p class="visible-xs text-center">
<span class="label label-warning">NSC</span> : This flag tells you that the shift needs a Super Co-operator
</p>
<div class="visible-xs" t-foreach="task_templates" t-as="template">
<ul class="list-group">
<li class="list-group-item">
<t t-esc="template.planning_id.name"/> :
<t t-esc="template.day_nb_id.name"/>
</td>
<td>
<t t-esc='float_to_time(template.start_time)' /> -
<t t-esc='float_to_time(template.end_time)'/>
</td>
<td>
<span class="label label-warning pull-right"
t-if="not template.super_coop_id">
NSC
</span>
</li>
<li class="list-group-item">
<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>
<span class="badge"
t-if="template.remaining_worker > 0">
<t t-esc="template.remaining_worker"/> space(s)
</span>
<span class="badge"
t-if="template.remaining_worker == 0">
full
</span>
</li>
</ul>
</div>
<table class="hidden-xs table table-striped">
<thead>
<tr>
<th>Week</th>
<th class="hidden-sm">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 class="hidden-sm">
<t t-esc="template.name"/>
</td>
<td>
<t t-esc="template.day_nb_id.name"/>
</td>
<td>
<t t-esc='float_to_time(template.start_time)' /> -
<t t-esc='float_to_time(template.end_time)'/>
</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>
</div>
</section>
</t>
</template>
<!-- Shift page -->
<template id="shift_template" name="Shift for irregular worker">
<!-- Available shifts for irregular workers -->
<template
id="shift_template"
name="Available Shifts for Irregular Workers"
page="True">
<t t-call="website.layout">
<div class="container">
<h1>Available 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_and_count">
<div class="oe_structure"/>
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">
Available Shifts for Irregular Workers
</h1>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<p class="text-center">
Subscribe via <a href="mailto:volant@bees-coop.be">volant@bees-coop.be</a>
</p>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<section class="wrap">
<div class="container">
<div class="row">
<div class="visible-xs" t-foreach="shift_templates" t-as="shift_and_count">
<t t-set="count" t-value="shift_and_count[0]" />
<t t-set="shift" t-value="shift_and_count[1]" />
<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>
<ul class="list-group">
<li class="list-group-item">
<t t-esc="time.strftime('%A %d %B %Y', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<span t-field="shift.start_time" t-field-options='{"format": "HH:mm"}'/> -
<span t-field="shift.end_time" t-field-options='{"format": "HH:mm"}'/>
</td>
<td>
<t t-esc="shift.task_template_id.name"/>
</td>
<td>
</li>
<li class="list-group-item">
<t t-esc="shift.task_type_id.name"/>
</td>
<td class="text-center">
<t t-esc="count"/>
</td>
</tr>
</t>
</tbody>
</table>
</div>
<span class="badge">
<t t-esc="count"/> space(s)
</span>
</li>
</ul>
</div>
<table class="hidden-xs table table-striped">
<thead>
<tr>
<th>Day</th>
<th>Date</th>
<th>Time</th>
<th class="hidden-sm">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_and_count">
<t t-set="count" t-value="shift_and_count[0]" />
<t t-set="shift" t-value="shift_and_count[1]" />
<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.start_time" t-field-options='{"format": "HH:mm"}'/> -
<span t-field="shift.end_time" t-field-options='{"format": "HH:mm"}'/>
</td>
<td class="hidden-sm">
<t t-esc="shift.task_template_id.name"/>
</td>
<td>
<t t-esc="shift.task_type_id.name"/>
</td>
<td class="text-center">
<t t-esc="count"/>
</td>
</tr>
</t>
</tbody>
</table>
</div> <!-- row -->
</div> <!-- container -->
</section>
</t>
</template>
</openerp>
Loading…
Cancel
Save