diff --git a/beesdoo_website_shift/__openerp__.py b/beesdoo_website_shift/__openerp__.py index 2ce89fa..ecd6f5a 100644 --- a/beesdoo_website_shift/__openerp__.py +++ b/beesdoo_website_shift/__openerp__.py @@ -16,7 +16,7 @@ 'author': 'Rémy Taymans', 'license': 'AGPL-3', - 'version': '9.0.2.2.0', + 'version': '9.0.2.3.0', 'website': "https://github.com/beescoop/Obeesdoo", 'category': 'Cooperative management', diff --git a/beesdoo_website_shift/controllers/main.py b/beesdoo_website_shift/controllers/main.py index 8580e83..0bbb7ab 100644 --- a/beesdoo_website_shift/controllers/main.py +++ b/beesdoo_website_shift/controllers/main.py @@ -184,10 +184,26 @@ class WebsiteShiftController(http.Controller): template = request.env['beesdoo.shift.template'] task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time") + # Get config + regular_highlight_rule = literal_eval( + request.env['ir.config_parameter'].get_param( + 'beesdoo_website_shift.regular_highlight_rule' + ) + ) + + task_tpls_data = [] + for task_tpl in task_templates: + has_enough_workers = ( + task_tpl.remaining_worker <= ( + task_tpl.worker_nb * regular_highlight_rule / 100 + ) + ) + task_tpls_data.append((task_tpl, has_enough_workers)) + return request.render( 'beesdoo_website_shift.public_shift_template_regular_worker', { - 'task_templates': task_templates, + 'task_tpls_data': task_tpls_data, 'float_to_time': float_to_time, } ) diff --git a/beesdoo_website_shift/data/res_config_data.xml b/beesdoo_website_shift/data/res_config_data.xml index 2b23c04..d75440d 100644 --- a/beesdoo_website_shift/data/res_config_data.xml +++ b/beesdoo_website_shift/data/res_config_data.xml @@ -33,5 +33,9 @@ beesdoo_website_shift.regular_next_shift_limit 13 + + beesdoo_website_shift.regular_highlight_rule + 20 + diff --git a/beesdoo_website_shift/models/res_config.py b/beesdoo_website_shift/models/res_config.py index c1d1aa3..5b7f751 100644 --- a/beesdoo_website_shift/models/res_config.py +++ b/beesdoo_website_shift/models/res_config.py @@ -18,6 +18,8 @@ PARAMS = [ 'beesdoo_website_shift.regular_past_shift_limit'), ('regular_next_shift_limit', 'beesdoo_website_shift.regular_next_shift_limit'), + ('regular_highlight_rule', + 'beesdoo_website_shift.regular_highlight_rule'), ] @@ -51,6 +53,10 @@ class WebsiteShiftConfigSettings(models.TransientModel): regular_next_shift_limit = fields.Integer( help="Maximun number of next shift that will be shown" ) + regular_highlight_rule = fields.Integer( + help="Treshold (in %) of available space in a shift that trigger the " + "the highlight of a shift template." + ) @api.multi def set_params(self): @@ -119,3 +125,12 @@ class WebsiteShiftConfigSettings(models.TransientModel): .get_param('beesdoo_website_shift.regular_next_shift_limit') ) } + + @api.multi + def get_default_regular_highlight_rule(self): + return { + 'regular_next_shift_limit': int( + self.env['ir.config_parameter'] + .get_param('beesdoo_website_shift.regular_highlight_rule') + ) + } diff --git a/beesdoo_website_shift/views/shift_website_templates.xml b/beesdoo_website_shift/views/shift_website_templates.xml index c9f11b1..bc261f7 100644 --- a/beesdoo_website_shift/views/shift_website_templates.xml +++ b/beesdoo_website_shift/views/shift_website_templates.xml @@ -64,8 +64,11 @@
-
-
+
+ + + +
: @@ -104,9 +107,11 @@ - + + + - +