Browse Source

[ADD] website_shift: Past shifts on personal page

Add a list of the previous shifts for a worker.
pull/33/head
Rémy Taymans 6 years ago
parent
commit
f0062bc741
  1. 36
      beesdoo_website_shift/controllers/main.py
  2. 8
      beesdoo_website_shift/data/res_config_data.xml
  3. 25
      beesdoo_website_shift/models/res_config.py
  4. 89
      beesdoo_website_shift/views/my_shift_website_templates.xml
  5. 36
      beesdoo_website_shift/views/res_config_views.xml

36
beesdoo_website_shift/controllers/main.py

@ -133,6 +133,7 @@ class WebsiteShiftController(http.Controller):
template_context.update(self.my_shift_worker_status())
template_context.update(self.my_shift_next_shifts())
template_context.update(self.my_shift_past_shifts())
template_context.update(self.available_shift_irregular_worker(
irregular_enable_sign_up, nexturl
))
@ -163,6 +164,7 @@ class WebsiteShiftController(http.Controller):
template_context.update(self.my_shift_worker_status())
template_context.update(self.my_shift_next_shifts())
template_context.update(self.my_shift_past_shifts())
template_context.update(
{
'task_templates': task_templates,
@ -259,6 +261,40 @@ class WebsiteShiftController(http.Controller):
'subscribed_shifts': subscribed_shifts,
}
def my_shift_past_shifts(self):
"""
Return template variables for 'beesdoo_website_shift.my_shift_past_shifts' template
"""
# Get current user
cur_user = request.env['res.users'].browse(request.uid)
# Get config
past_shift_limit = 0
if self.is_user_irregular():
past_shift_limit = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_past_shift_limit'))
if self.is_user_regular():
past_shift_limit = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.regular_past_shift_limit'))
# Get shifts where user was subscribed
now = datetime.now()
if past_shift_limit > 0:
past_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",
limit=past_shift_limit,
)
else:
past_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",
)
return {
'past_shifts': past_shifts,
}
def my_shift_worker_status(self):
"""
Return template variables for 'beesdoo_website_shift.my_shift_worker_status_*' template

8
beesdoo_website_shift/data/res_config_data.xml

@ -21,5 +21,13 @@
<field name="key">beesdoo_website_shift.irregular_enable_sign_up</field>
<field name="value">True</field>
</record>
<record id="beesdoo_website_shift.irregular_past_shift_limit" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.irregular_past_shift_limit</field>
<field name="value">10</field>
</record>
<record id="beesdoo_website_shift.regular_past_shift_limit" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.regular_past_shift_limit</field>
<field name="value">10</field>
</record>
</data>
</openerp>

25
beesdoo_website_shift/models/res_config.py

@ -11,6 +11,8 @@ PARAMS = [
('highlight_rule', 'beesdoo_website_shift.highlight_rule'),
('hide_rule', 'beesdoo_website_shift.hide_rule'),
('irregular_enable_sign_up', 'beesdoo_website_shift.irregular_enable_sign_up'),
('irregular_past_shift_limit', 'beesdoo_website_shift.irregular_past_shift_limit'),
('regular_past_shift_limit', 'beesdoo_website_shift.regular_past_shift_limit'),
]
@ -19,6 +21,7 @@ class WebsiteShiftConfigSettings(models.TransientModel):
_name = 'beesdoo.website.shift.config.settings'
_inherit = 'res.config.settings'
# Irregular worker settings
irregular_shift_limit = fields.Integer(
help="Maximum shift that will be shown"
)
@ -31,6 +34,14 @@ class WebsiteShiftConfigSettings(models.TransientModel):
irregular_enable_sign_up = fields.Boolean(
help="Enable shift sign up for irregular worker"
)
irregular_past_shift_limit = fields.Integer(
help="Maximum past shift that will be shown for irregular worker"
)
# Regular worker settings
regular_past_shift_limit = fields.Integer(
help="Maximum past shift that will be shown for regular worker"
)
@api.multi
def set_params(self):
@ -65,3 +76,17 @@ class WebsiteShiftConfigSettings(models.TransientModel):
'irregular_enable_sign_up': literal_eval(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_enable_sign_up'))
}
@api.multi
def get_default_irregular_past_shift_limit(self):
return {
'irregular_past_shift_limit': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_past_shift_limit'))
}
@api.multi
def get_default_regular_past_shift_limit(self):
return {
'regular_past_shift_limit': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.regular_past_shift_limit'))
}

89
beesdoo_website_shift/views/my_shift_website_templates.xml

@ -173,6 +173,91 @@
</template>
<template
id="my_shift_past_shifts"
name="My Shift : Past Shifts">
<div class="oe_structure"/>
<section class="wrap">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>
Your past shifts
</h2>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
<div class="visible-xs" t-foreach="past_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"}'/>
</div>
</div>
<div class="panel-body">
<t t-esc="shift.task_type_id.name"/>
</div>
</div>
</div>
<table class="hidden-xs table table-striped" t-if="past_shifts">
<thead>
<tr>
<th>Day</th>
<th>Date</th>
<th>Time</th>
<th>Type of Shift</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<t t-foreach="past_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>
<td>
<t t-esc="shift.stage_id.name"/>
</td>
</tr>
</t>
</tbody>
</table>
<section class="wrap" t-if="not past_shifts">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="alert alert-info">
<strong>Info !</strong> You don't have any past shift.
</div>
</div>
</div>
</div>
</section>
<div class="oe_structure"/>
</template>
<template
id="available_shift_irregular_worker"
name="Available Shift for Irregular Worker">
@ -434,6 +519,8 @@
<t t-call="beesdoo_website_shift.my_shift_next_shifts"/>
<t t-call="beesdoo_website_shift.my_shift_past_shifts"/>
</div> <!-- col-md-8 -->
</div> <!-- row -->
</div> <!-- container -->
@ -519,6 +606,8 @@
<t t-call="beesdoo_website_shift.available_shift_irregular_worker"/>
<t t-call="beesdoo_website_shift.my_shift_past_shifts"/>
</div> <!-- col-md-8 -->
</div> <!-- row -->
</div> <!-- container -->

36
beesdoo_website_shift/views/res_config_views.xml

@ -31,6 +31,27 @@
<label for="irregular_enable_sign_up"/>
<field name="irregular_enable_sign_up"/>
</div>
<div>
<label for="irregular_past_shift_limit"/>
<field name="irregular_past_shift_limit"/>
</div>
</form>
</field>
</record>
<record id="view_website_shift_config_regular" model="ir.ui.view">
<field name="name">Website Shift Settings Regular Worker</field>
<field name="model">beesdoo.website.shift.config.settings</field>
<field name="arch" type="xml">
<form string="Configure Website Shift Regular Worker" class="oe_form_configuration">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
<button string="Cancel" type="object" name="cancel" class="oe_link" special="cancel"/>
</header>
<div>
<label for="regular_past_shift_limit"/>
<field name="regular_past_shift_limit"/>
</div>
</form>
</field>
</record>
@ -43,6 +64,14 @@
<field name="target">inline</field>
</record>
<record id="action_website_shift_config_regular" model="ir.actions.act_window">
<field name="name">Website Shift Settings Regular Worker</field>
<field name="res_model">beesdoo.website.shift.config.settings</field>
<field name="view_id" ref="view_website_shift_config_regular"/>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
<menuitem
id="menu_website_shift_root"
name="Shift"
@ -56,5 +85,12 @@
parent="menu_website_shift_root"
sequence="1"/>
<menuitem
id="menu_website_shift_regular"
name="Regular Shift"
action="action_website_shift_config_regular"
parent="menu_website_shift_root"
sequence="10"/>
</data>
</openerp>
Loading…
Cancel
Save