You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.8 KiB

  1. # -*- coding: utf8 -*-
  2. from datetime import datetime
  3. from math import floor
  4. from openerp import http
  5. from openerp.http import request
  6. class ShiftPortalController(http.Controller):
  7. @http.route('/shift_irregular_worker', auth='public', website=True)
  8. def shift_irregular_worker(self, **kwargs):
  9. # Get all the shifts in the future with no worker
  10. now = datetime.now()
  11. shifts = request.env['beesdoo.shift.shift'].sudo().search(
  12. [('start_time', '>', now.strftime("%Y-%m-%d %H:%M:%S")),
  13. ('worker_id', '=', False)],
  14. order="start_time, task_template_id, task_type_id",
  15. )
  16. # Loop on all the shifts
  17. shift_templates = []
  18. current_template = None
  19. current_shift_template = None
  20. current_remaining_space = 0
  21. for shift in shifts:
  22. # For a planning id, count the number of shift that don't
  23. # have a worker.
  24. if shift.task_template_id == current_template:
  25. # If we are in the same template then update the number
  26. # of available sapce
  27. current_remaining_space = current_remaining_space + 1
  28. else:
  29. if current_shift_template:
  30. # Save the old current_shift_template
  31. current_shift_template.remaining_space = current_remaining_space
  32. shift_templates.append(current_shift_template)
  33. # Initiate the new current_shift_template
  34. current_template = shift.task_template_id
  35. current_remaining_space = 1
  36. current_shift_template = ShiftTemplate(shift,
  37. shift.start_time,
  38. shift.end_time,
  39. current_template.name,
  40. current_template.task_type_id.name)
  41. return request.render(
  42. 'beesdoo_portal_shift.shift_template',
  43. {'shift_templates': shift_templates}
  44. )
  45. @http.route('/shift_template_regular_worker', auth='public', website=True)
  46. def shift_template_regular_worker(self, **kwargs):
  47. # Get all the task template
  48. task_templates = request.env['beesdoo.shift.template'].sudo().search(
  49. [],
  50. order="planning_id, day_nb_id, start_time",
  51. )
  52. # Compute start_time and end_time
  53. task_template_times = []
  54. cur_start_hour = 0
  55. cur_start_minute = 0
  56. cur_end_hour = 0
  57. cur_end_minute = 0
  58. for template in task_templates:
  59. cur_start_hour = floor(template.start_time)
  60. cur_start_minute = floor((template.start_time -
  61. cur_start_hour) * 60)
  62. cur_end_hour = floor(template.end_time)
  63. cur_end_minute = floor((template.end_time -
  64. cur_end_hour) * 60)
  65. task_template_times.append(
  66. {"start_hour": "%02d" % cur_start_hour,
  67. "start_minute": "%02d" % cur_start_minute,
  68. "end_hour": "%02d" % cur_end_hour,
  69. "end_minute": "%02d" % cur_end_minute}
  70. )
  71. return request.render(
  72. 'beesdoo_portal_shift.task_template',
  73. {'task_templates': task_templates,
  74. 'task_template_times': task_template_times}
  75. )
  76. class ShiftTemplate(object):
  77. shift = None
  78. start_time = None
  79. end_time = None
  80. name = ''
  81. task_type = ''
  82. remaining_space = 0
  83. def __init__(self, shift, start_time, end_time, name, task_type):
  84. self.shift = shift
  85. self.start_time = start_time
  86. self.end_time = end_time
  87. self.name = name
  88. self.task_type = task_type