Browse Source

[ADD] website_shift: Irregular personal work page

Add personal shift page for irregular worker that allows you to
subscribe to a shift.
pull/33/head
Rémy Taymans 7 years ago
parent
commit
fd2839985c
  1. 58
      beesdoo_website_shift/controllers/main.py
  2. 369
      beesdoo_website_shift/views/shift_website_templates.xml

58
beesdoo_website_shift/controllers/main.py

@ -8,8 +8,36 @@ from openerp.addons.beesdoo_shift.models.planning import float_to_time
class WebsiteShiftController(http.Controller):
@http.route('/shift_irregular_worker', auth='public', website=True)
@http.route('/shift', auth='user', website=True)
def shift(self, **kwargs):
cur_user = request.env['res.users'].browse(request.uid)
working_mode = cur_user.partner_id.working_mode
if working_mode == 'irregular':
return self.shift_irregular_worker()
if working_mode == 'regular':
return self.shift_template_regular_worker()
return request.render(
'beesdoo_website_shift.shift',
{
'user': cur_user,
}
)
@http.route('/shift/<model("beesdoo.shift.shift"):shift>/subscribe', auth='user', website=True)
def subscribe_to_shift(self, shift=None, **kwargs):
# Get current user
cur_user = request.env['res.users'].browse(request.uid)
if (cur_user.partner_id.working_mode == 'irregular'
and shift
and not shift.worker_id):
shift.worker_id = cur_user.partner_id
return request.redirect(kwargs['nexturl'])
def shift_irregular_worker(self, **kwargs):
# Get current user
cur_user = request.env['res.users'].browse(request.uid)
# Get all the shifts in the future with no worker
now = datetime.now()
shifts = request.env['beesdoo.shift.shift'].sudo().search(
@ -18,6 +46,13 @@ class WebsiteShiftController(http.Controller):
order="start_time, task_template_id, task_type_id",
)
# Get shifts where user is subscribed
subscribed_shifts = request.env['beesdoo.shift.shift'].sudo().search(
[('start_time', '>', now.strftime("%Y-%m-%d %H:%M:%S")),
('worker_id', '=', cur_user.partner_id.id)],
order="start_time, task_template_id, task_type_id",
)
# Get config
irregular_shift_limit = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_shift_limit'))
@ -31,24 +66,35 @@ class WebsiteShiftController(http.Controller):
groupby_func = lambda s: (s.task_template_id, s.start_time, s.task_type_id)
groupby_iter = groupby(shifts, groupby_func)
shifts_and_count = []
shifts_count_subscribed = []
nb_displayed_shift = 0 # Number of shift displayed
for (keys, grouped_shifts) in groupby_iter:
(task_template, _, _) = keys
(task_template, start_time, task_type) = keys
nb_displayed_shift = nb_displayed_shift + 1
s = list(grouped_shifts)
# Compute available space
free_space = len(s)
# Is the current user subscribed to this task_template
is_subscribed = any(
(sub_shift.task_template_id == task_template and
sub_shift.start_time == start_time and
sub_shift.task_type_id == task_type)
for sub_shift in subscribed_shifts)
if free_space >= task_template.worker_nb * hide_rule:
shifts_and_count.append([free_space, s[0]])
shifts_count_subscribed.append([s[0], free_space, is_subscribed])
# Stop showing shifts if the limit is reached
if irregular_shift_limit > 0 and nb_displayed_shift >= irregular_shift_limit:
break
return request.render(
'beesdoo_website_shift.shift_template',
'beesdoo_website_shift.irregular_worker',
{
'shift_templates': shifts_and_count,
'partner': cur_user.partner_id,
'status': cur_user.partner_id.cooperative_status_ids,
'shift_templates': shifts_count_subscribed,
'highlight_rule': highlight_rule,
'nexturl': '/shift',
'subscribed_shifts': subscribed_shifts,
}
)

369
beesdoo_website_shift/views/shift_website_templates.xml

@ -3,19 +3,23 @@
<!-- 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="name">Shifts</field>
<field name="url">/shift</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>
<!-- Shift -->
<template
id="shift"
name="Shift"
page="True">
<t t-call="website.layout">
<t t-esc="user.partner_id.working_mode"/>
</t>
</template>
<!-- Available Tasks Templates for Regular Workers -->
<template
id="task_template"
@ -141,10 +145,10 @@
</t>
</template>
<!-- Available shifts for irregular workers -->
<!-- Shifts for Irregular Workers -->
<template
id="shift_template"
name="Available Shifts for Irregular Workers"
id="irregular_worker"
name="Shifts for Irregular Workers"
page="True">
<t t-call="website.layout">
@ -155,7 +159,7 @@
<div class="row">
<div class="col-md-12">
<h1 class="text-center">
Available Shifts for Irregular Workers
Your shifts
</h1>
</div>
</div>
@ -167,82 +171,297 @@
<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>
<div class="col-xs-12 col-md-4 pull-right">
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>
Worker status
</h2>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<p>
<label>Working Mode:</label>
<t t-esc="dict(status.fields_get(allfields=['working_mode'])['working_mode']['selection'])[status.working_mode]"/>
</p>
<p>
<label>Status:</label>
<t t-esc="dict(status.fields_get(allfields=['status'])['status']['selection'])[status.status]"/>
</p>
<p>
<label>Absence Counter:</label>
<t t-esc="status.irregular_absence_counter"/>
</p>
<t t-if="status.holiday_start_time">
<p>
<label>Holiday start time:</label>
<t t-esc="status.holiday_start_time"/>
</p>
<p>
<label>Holiday end time:</label>
<t t-esc="status.holiday_end_time"/>
</p>
</t>
<p>
<label>Irregular start date:</label>
<t t-esc="status.irregular_start_date"/>
</p>
<p>
<label>Irregular absence date:</label>
<t t-if="status.irregular_absence_date">
<t t-esc="status.irregular_absence_date"/>
</t>
<t t-if="not status.irregular_absence_date">
No absence
</t>
</p>
<div class="oe_structure"/>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<div class="col-xs-12 col-md-8">
<section class="wrap">
<div class="container">
<div class="row">
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>
Your next shifts
</h2>
</div>
</div>
</div>
</section>
<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]" />
<ul class="list-group">
<li t-attf-class="{{ 'list-group-item list-group-item-danger' if count >= highlight_rule else '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"}'/>
</li>
<li t-attf-class="{{ 'list-group-item list-group-item-danger' if count >= highlight_rule else 'list-group-item' }}">
<t t-esc="shift.task_type_id.name"/>
<span class="badge">
<t t-esc="count"/> space(s)
</span>
</li>
</ul>
</div>
<div class="oe_structure"/>
<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 t-attf-class="{{ 'danger' if count >= highlight_rule else '' }}">
<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>
<div class="visible-xs" t-foreach="subscribed_shifts" t-as="shift">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<div class="panel-title">
<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 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>
</div>
</div>
<div class="panel-body">
<t t-esc="shift.task_type_id.name"/>
</div>
</div>
</div>
<table class="hidden-xs table table-striped">
<thead>
<tr>
<th>Day</th>
<th>Date</th>
<th>Time</th>
<th>Type of Shift</th>
</tr>
</t>
</tbody>
</table>
</thead>
<tbody>
<t t-foreach="subscribed_shifts" 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.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_type_id.name"/>
</td>
</tr>
</t>
</tbody>
</table>
<section class="wrap" t-if="not subscribed_shifts">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="alert alert-warning">
<strong>Warning !</strong> You have not yet signed up to a shift.
</div>
</div>
</div>
</div>
</section>
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>
Available Shifts
</h2>
</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">
Explanation text
</p>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<div class="visible-xs" t-foreach="shift_templates" t-as="shift_count_subscribed">
<t t-set="shift" t-value="shift_count_subscribed[0]" />
<t t-set="count" t-value="shift_count_subscribed[1]" />
<t t-set="is_subscribed" t-value="shift_count_subscribed[2]" />
<t t-set="highlight_class" t-value="'panel-danger' if count >= highlight_rule else 'panel-default'"/>
<div t-att-class="'panel %s' % highlight_class">
<div class="panel-heading clearfix">
<div class="panel-title pull-left">
<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"}'/>
</div>
<div class="label label-default pull-right">
<t t-esc="count"/> space(s)
</div>
</div>
<div class="panel-body clearfix">
<t t-esc="shift.task_type_id.name"/>
<t t-if="is_subscribed">
<div class="label label-success pull-right">
<span class="fa fa-check" aria-hidden="true"></span>
Subscribed
</div>
</t>
<t t-if="not is_subscribed">
<button type="button" class="btn btn-default btn-sm pull-right" data-toggle="modal"
t-att-data-target="'#subscribe-shift-%s' % shift.id">
<span class="fa fa-user-plus" aria-hidden="true"></span>
Subscribe
</button>
</t>
</div>
</div>
</div>
<table class="hidden-xs table table-striped">
<thead>
<tr>
<th>Day</th>
<th>Date</th>
<th>Time</th>
<th>Type of Shift</th>
<th class="text-center">Available Spaces</th>
<th class="text-center">Subscribed</th>
</tr>
</thead>
<tbody>
<t t-foreach="shift_templates" t-as="shift_count_subscribed">
<t t-set="shift" t-value="shift_count_subscribed[0]" />
<t t-set="count" t-value="shift_count_subscribed[1]" />
<t t-set="is_subscribed" t-value="shift_count_subscribed[2]" />
<tr t-attf-class="{{ 'danger' if count >= highlight_rule else '' }}">
<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>
<t t-esc="shift.task_type_id.name"/>
</td>
<td class="text-center">
<t t-esc="count"/>
</td>
<td class="text-center">
<t t-if="is_subscribed">
<div class="label label-success">
<span class="fa fa-check" aria-hidden="true"></span>
Subscribed
</div>
</t>
<t t-if="not is_subscribed">
<button type="button" class="btn btn-default btn-sm" data-toggle="modal"
t-att-data-target="'#subscribe-shift-%s' % shift.id">
<span class="fa fa-user-plus" aria-hidden="true"></span>
Subscribe
</button>
</t>
</td>
</tr>
</t>
</tbody>
</table>
<!-- Subscribe check -->
<t t-foreach="shift_templates" t-as="shift_count_subscribed">
<t t-set="shift" t-value="shift_count_subscribed[0]" />
<t t-set="count" t-value="shift_count_subscribed[1]" />
<t t-set="is_subscribed" t-value="shift_count_subscribed[2]" />
<div class="modal fade" t-att-id="'subscribe-shift-%s' % shift.id" tabindex="-1" role="dialog"
t-att-aria-labelledby="'subscribe-shift-%s-label' % shift.id">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" t-att-id="'subscribe-shift-%s-label' % shift.id">
Are you shure you want to subscribe to this shift?
</h4>
</div>
<div class="modal-body">
<t t-esc="time.strftime('%A', time.strptime(shift.start_time, '%Y-%m-%d %H:%M:%S'))"/>
<t t-esc="time.strftime('%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"}'/><br/>
<t t-esc="shift.task_type_id.name"/><br/>
<t t-esc="count"/> available space(s)
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a class="btn btn-primary"
t-att-href="'/shift/%s/subscribe?nexturl=%s' % (shift.id, nexturl)">
Subscribe
</a>
</div>
</div>
</div>
</div>
</t>
<div class="oe_structure"/>
</div> <!-- col-md-8 -->
</div> <!-- row -->
</div> <!-- container -->
</section>
<div class="oe_structure"/>
</t>
</template>
</openerp>
Loading…
Cancel
Save