diff --git a/beesdoo_portal_shift/controllers/main.py b/beesdoo_portal_shift/controllers/main.py index d5b1538..501a583 100644 --- a/beesdoo_portal_shift/controllers/main.py +++ b/beesdoo_portal_shift/controllers/main.py @@ -1,10 +1,11 @@ # -*- coding: utf8 -*- from datetime import datetime -from math import floor - +from itertools import groupby from openerp import http from openerp.http import request +from openerp.addons.beesdoo_shift.models.planning import float_to_time + class ShiftPortalController(http.Controller): @http.route('/shift_irregular_worker', auth='public', website=True) @@ -16,84 +17,25 @@ class ShiftPortalController(http.Controller): ('worker_id', '=', False)], order="start_time, task_template_id, task_type_id", ) - # Loop on all the shifts - shift_templates = [] - current_template = None - current_shift_template = None - current_remaining_space = 0 - for shift in shifts: - # For a planning id, count the number of shift that don't - # have a worker. - if shift.task_template_id == current_template: - # If we are in the same template then update the number - # of available sapce - current_remaining_space = current_remaining_space + 1 - else: - if current_shift_template: - # Save the old current_shift_template - current_shift_template.remaining_space = current_remaining_space - shift_templates.append(current_shift_template) - # Initiate the new current_shift_template - current_template = shift.task_template_id - current_remaining_space = 1 - current_shift_template = ShiftTemplate(shift, - shift.start_time, - shift.end_time, - current_template.name, - current_template.task_type_id.name) + 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]]) - return request.render( - 'beesdoo_portal_shift.shift_template', - {'shift_templates': shift_templates} + return request.render('beesdoo_portal_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 - task_templates = request.env['beesdoo.shift.template'].sudo().search( - [], - order="planning_id, day_nb_id, start_time", - ) - - # Compute start_time and end_time - task_template_times = [] - cur_start_hour = 0 - cur_start_minute = 0 - cur_end_hour = 0 - cur_end_minute = 0 - for template in task_templates: - cur_start_hour = floor(template.start_time) - cur_start_minute = floor((template.start_time - - cur_start_hour) * 60) - cur_end_hour = floor(template.end_time) - cur_end_minute = floor((template.end_time - - cur_end_hour) * 60) - task_template_times.append( - {"start_hour": "%02d" % cur_start_hour, - "start_minute": "%02d" % cur_start_minute, - "end_hour": "%02d" % cur_end_hour, - "end_minute": "%02d" % cur_end_minute} - ) - - return request.render( - 'beesdoo_portal_shift.task_template', - {'task_templates': task_templates, - 'task_template_times': task_template_times} - ) - - -class ShiftTemplate(object): - shift = None - start_time = None - end_time = None - name = '' - task_type = '' - remaining_space = 0 - - def __init__(self, shift, start_time, end_time, name, task_type): - self.shift = shift - self.start_time = start_time - self.end_time = end_time - self.name = name - self.task_type = task_type + template = request.env['beesdoo.shift.template'] + task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time") + + return request.render('beesdoo_portal_shift.task_template', + { + 'task_templates': task_templates, + 'float_to_time': float_to_time + } + ) \ No newline at end of file diff --git a/beesdoo_portal_shift/views/shift_portal_templates.xml b/beesdoo_portal_shift/views/shift_portal_templates.xml index 00dcbec..6e12fcb 100644 --- a/beesdoo_portal_shift/views/shift_portal_templates.xml +++ b/beesdoo_portal_shift/views/shift_portal_templates.xml @@ -44,8 +44,8 @@ - : - - : + - + @@ -92,7 +92,9 @@ - + + + @@ -101,17 +103,17 @@ - - - + - + - + - + - +