diff --git a/beesdoo_website_shift/__openerp__.py b/beesdoo_website_shift/__openerp__.py index ea05970..bbe19a3 100644 --- a/beesdoo_website_shift/__openerp__.py +++ b/beesdoo_website_shift/__openerp__.py @@ -19,6 +19,5 @@ 'data': [ 'views/shift_website_templates.xml', - 'data/config_data.xml', ] } diff --git a/beesdoo_website_shift/controllers/main.py b/beesdoo_website_shift/controllers/main.py index 14f205a..885ed91 100644 --- a/beesdoo_website_shift/controllers/main.py +++ b/beesdoo_website_shift/controllers/main.py @@ -14,28 +14,50 @@ class ShiftPortalController(http.Controller): now = datetime.now() shifts = request.env['beesdoo.shift.shift'].sudo().search( [('start_time', '>', now.strftime("%Y-%m-%d %H:%M:%S")), - ('worker_id', '=', False)], + ('worker_id', '=', False)], order="start_time, task_template_id, task_type_id", ) + # 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 = [] - for _, val in groupby(shifts, lambda s: s.task_template_id): - s = [v for v in val] - shifts_and_count.append([len(s), s[0]]) + for (keys, grouped_shifts) in groupby_iter: + (task_template, start_time, task_type) = keys + 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 len(s) >= 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: + shifts_and_count.append([free_space, s[0]]) - return request.render('beesdoo_website_shift.shift_template', - {'shift_templates': shifts_and_count} + return request.render( + 'beesdoo_website_shift.shift_template', + { + 'shift_templates': shifts_and_count + } ) @http.route('/shift_template_regular_worker', auth='public', website=True) def shift_template_regular_worker(self, **kwargs): # Get all the task template template = request.env['beesdoo.shift.template'] - task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time") + task_templates = template.sudo().search( + [], + order="planning_id, day_nb_id, start_time" + ) - return request.render('beesdoo_website_shift.task_template', + return request.render( + 'beesdoo_website_shift.task_template', { - 'task_templates': task_templates, - 'float_to_time': float_to_time + 'task_templates': task_templates, + 'float_to_time': float_to_time } - ) \ No newline at end of file + ) diff --git a/beesdoo_website_shift/data/config_data.xml b/beesdoo_website_shift/data/config_data.xml deleted file mode 100644 index f028307..0000000 --- a/beesdoo_website_shift/data/config_data.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Shifts Irregular - /shift_irregular_worker - - 50 - - - Shifts Regular - /shift_template_regular_worker - - 51 - - - diff --git a/beesdoo_website_shift/views/shift_website_templates.xml b/beesdoo_website_shift/views/shift_website_templates.xml index 8a00e24..1bbd66a 100644 --- a/beesdoo_website_shift/views/shift_website_templates.xml +++ b/beesdoo_website_shift/views/shift_website_templates.xml @@ -1,5 +1,22 @@ - + + + + + Shifts Irregular + /shift_irregular_worker + + 50 + + + Shifts Regular + /shift_template_regular_worker + + 51 + + + + - -