diff --git a/beesdoo_website_shift/__init__.py b/beesdoo_website_shift/__init__.py
index e046e49..91c5580 100644
--- a/beesdoo_website_shift/__init__.py
+++ b/beesdoo_website_shift/__init__.py
@@ -1 +1,2 @@
from . import controllers
+from . import models
diff --git a/beesdoo_website_shift/__openerp__.py b/beesdoo_website_shift/__openerp__.py
index bbe19a3..24d1d7b 100644
--- a/beesdoo_website_shift/__openerp__.py
+++ b/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',
]
}
diff --git a/beesdoo_website_shift/controllers/main.py b/beesdoo_website_shift/controllers/main.py
index 3b12d54..55b5757 100644
--- a/beesdoo_website_shift/controllers/main.py
+++ b/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,
}
)
diff --git a/beesdoo_website_shift/data/res_config_data.xml b/beesdoo_website_shift/data/res_config_data.xml
new file mode 100644
index 0000000..f8857b5
--- /dev/null
+++ b/beesdoo_website_shift/data/res_config_data.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ beesdoo_website_shift.irregular_shift_limit
+ 0
+
+
+ beesdoo_website_shift.highlight_rule
+ 3
+
+
+ beesdoo_website_shift.hide_rule
+ 20
+
+
+
diff --git a/beesdoo_website_shift/models/__init__.py b/beesdoo_website_shift/models/__init__.py
new file mode 100644
index 0000000..ab480f8
--- /dev/null
+++ b/beesdoo_website_shift/models/__init__.py
@@ -0,0 +1 @@
+from . import res_config
diff --git a/beesdoo_website_shift/models/res_config.py b/beesdoo_website_shift/models/res_config.py
new file mode 100644
index 0000000..d722307
--- /dev/null
+++ b/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'))
+ }
diff --git a/beesdoo_website_shift/views/res_config_views.xml b/beesdoo_website_shift/views/res_config_views.xml
new file mode 100644
index 0000000..a17a17f
--- /dev/null
+++ b/beesdoo_website_shift/views/res_config_views.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+ Website Shift Settings
+ beesdoo.website.shift.config.settings
+
+
+
+
+
+
+ Website Shift Settings
+ beesdoo.website.shift.config.settings
+
+ form
+ inline
+
+
+
+
+
+
+
+
diff --git a/beesdoo_website_shift/views/shift_website_templates.xml b/beesdoo_website_shift/views/shift_website_templates.xml
index e7dba77..83f46d8 100644
--- a/beesdoo_website_shift/views/shift_website_templates.xml
+++ b/beesdoo_website_shift/views/shift_website_templates.xml
@@ -17,8 +17,8 @@
-
@@ -64,7 +64,7 @@
-
- :
+ :
-
@@ -142,8 +142,8 @@
-
@@ -186,12 +186,12 @@
- -
+
-
-
- -
+
-
space(s)
@@ -215,7 +215,7 @@
-
+
|