Browse Source

[ADD] website_shift: Add configuration

irregular_shift_limit: Maximum shift that will be shown
highlight_rule: Treshold of available space in a shift that trigger the
                highlight of the shift
hide_rule: Treshold ((available space)/(max space)) in percentage of
           available space under wich the shift is hidden
The last one replaces the old hide filter.
pull/33/head
Rémy Taymans 7 years ago
parent
commit
34122dcaa6
  1. 1
      beesdoo_website_shift/__init__.py
  2. 2
      beesdoo_website_shift/__openerp__.py
  3. 28
      beesdoo_website_shift/controllers/main.py
  4. 17
      beesdoo_website_shift/data/res_config_data.xml
  5. 1
      beesdoo_website_shift/models/__init__.py
  6. 51
      beesdoo_website_shift/models/res_config.py
  7. 52
      beesdoo_website_shift/views/res_config_views.xml
  8. 16
      beesdoo_website_shift/views/shift_website_templates.xml

1
beesdoo_website_shift/__init__.py

@ -1 +1,2 @@
from . import controllers
from . import models

2
beesdoo_website_shift/__openerp__.py

@ -18,6 +18,8 @@
'depends': ['website', 'beesdoo_shift'],
'data': [
'data/res_config_data.xml',
'views/shift_website_templates.xml',
'views/res_config_views.xml',
]
}

28
beesdoo_website_shift/controllers/main.py

@ -6,7 +6,7 @@ from openerp.http import request
from openerp.addons.beesdoo_shift.models.planning import float_to_time
class ShiftPortalController(http.Controller):
class WebsiteShiftController(http.Controller):
@http.route('/shift_irregular_worker', auth='public', website=True)
def shift_irregular_worker(self, **kwargs):
@ -18,27 +18,37 @@ class ShiftPortalController(http.Controller):
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'))
highlight_rule = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.highlight_rule'))
hide_rule = int(request.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.hide_rule')) / 100.0
# 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 = []
nb_displayed_shift = 0 # Number of shift displayed
for (keys, grouped_shifts) in groupby_iter:
(task_template, _, _) = keys
nb_displayed_shift = nb_displayed_shift + 1
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 free_space >= 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:
if free_space >= task_template.worker_nb * hide_rule:
shifts_and_count.append([free_space, s[0]])
# 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',
return request.render(
'beesdoo_website_shift.shift_template',
{
'shift_templates': shifts_and_count
'shift_templates': shifts_and_count,
'highlight_rule': highlight_rule,
}
)

17
beesdoo_website_shift/data/res_config_data.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="beesdoo_website_shift.irregular_shift_limit" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.irregular_shift_limit</field>
<field name="value">0</field>
</record>
<record id="beesdoo_website_shift.highlight_rule" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.highlight_rule</field>
<field name="value">3</field>
</record>
<record id="beesdoo_website_shift.hide_rule" model="ir.config_parameter">
<field name="key">beesdoo_website_shift.hide_rule</field>
<field name="value">20</field>
</record>
</data>
</openerp>

1
beesdoo_website_shift/models/__init__.py

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

51
beesdoo_website_shift/models/res_config.py

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
from openerp import fields, models, api
PARAMS = [
('irregular_shift_limit', 'beesdoo_website_shift.irregular_shift_limit'),
('highlight_rule', 'beesdoo_website_shift.highlight_rule'),
('hide_rule', 'beesdoo_website_shift.hide_rule'),
]
class WebsiteShiftConfigSettings(models.TransientModel):
_name = 'beesdoo.website.shift.config.settings'
_inherit = 'res.config.settings'
irregular_shift_limit = fields.Integer(
help="Maximum shift that will be shown"
)
highlight_rule = fields.Integer(
help="Treshold of available space in a shift that trigger the highlight of the shift"
)
hide_rule = fields.Integer(
help="Treshold ((available space)/(max space)) in percentage of available space under wich the shift is hidden"
)
@api.multi
def set_params(self):
self.ensure_one()
for field_name, key_name in PARAMS:
value = getattr(self, field_name)
self.env['ir.config_parameter'].set_param(key_name, str(value))
@api.multi
def get_default_irregular_shift_limit(self):
return {
'irregular_shift_limit': int(self.env['ir.config_parameter'].get_param(
'beesdoo_website_shift.irregular_shift_limit'))
}
@api.multi
def get_default_highlight_rule(self):
return {
'highlight_rule': int(self.env['ir.config_parameter'].get_param('beesdoo_website_shift.highlight_rule'))
}
@api.multi
def get_default_hide_rule(self):
return {
'hide_rule': int(self.env['ir.config_parameter'].get_param('beesdoo_website_shift.hide_rule'))
}

52
beesdoo_website_shift/views/res_config_views.xml

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_website_shift_config_irregular" model="ir.ui.view">
<field name="name">Website Shift Settings</field>
<field name="model">beesdoo.website.shift.config.settings</field>
<field name="arch" type="xml">
<form string="Configure Website Shift" 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="irregular_shift_limit"/>
<field name="irregular_shift_limit"/>
</div>
<div>
<label for="highlight_rule"/>
<field name="highlight_rule"/>
</div>
<div>
<label for="hide_rule"/>
<field name="hide_rule"/>
</div>
</form>
</field>
</record>
<record id="action_website_shift_configuration" model="ir.actions.act_window">
<field name="name">Website Shift Settings</field>
<field name="res_model">beesdoo.website.shift.config.settings</field>
<field name="view_id" ref="view_website_shift_config_irregular"/>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
<menuitem
id="menu_website_shift_root"
name="Shift"
parent="website.menu_website_configuration"
sequence="20"/>
<menuitem
id="menu_website_shift_irregular"
name="Irregular Shift"
action="action_website_shift_configuration"
parent="menu_website_shift_root"
sequence="1"/>
</data>
</openerp>

16
beesdoo_website_shift/views/shift_website_templates.xml

@ -17,8 +17,8 @@
</data>
<!-- Available Tasks Templates for Regular Workers -->
<template
id="task_template"
<template
id="task_template"
name="Available Tasks Templates for Regular Workers"
page="True">
<t t-call="website.layout">
@ -64,7 +64,7 @@
<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.planning_id.name"/> :
<t t-esc="template.day_nb_id.name"/>
<t t-esc='float_to_time(template.start_time)' /> -
<t t-esc='float_to_time(template.end_time)'/>
@ -142,8 +142,8 @@
</template>
<!-- Available shifts for irregular workers -->
<template
id="shift_template"
<template
id="shift_template"
name="Available Shifts for Irregular Workers"
page="True">
<t t-call="website.layout">
@ -186,12 +186,12 @@
<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 class="list-group-item">
<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 class="list-group-item">
<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)
@ -215,7 +215,7 @@
<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>
<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>

Loading…
Cancel
Save