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.

63 lines
2.4 KiB

  1. # -*- coding: utf8 -*-
  2. from datetime import datetime
  3. from itertools import groupby
  4. from openerp import http
  5. from openerp.http import request
  6. from openerp.addons.beesdoo_shift.models.planning import float_to_time
  7. class ShiftPortalController(http.Controller):
  8. @http.route('/shift_irregular_worker', auth='public', website=True)
  9. def shift_irregular_worker(self, **kwargs):
  10. # Get all the shifts in the future with no worker
  11. now = datetime.now()
  12. shifts = request.env['beesdoo.shift.shift'].sudo().search(
  13. [('start_time', '>', now.strftime("%Y-%m-%d %H:%M:%S")),
  14. ('worker_id', '=', False)],
  15. order="start_time, task_template_id, task_type_id",
  16. )
  17. # Grouby task_template_id, if no task_template_id is specified
  18. # then group by start_time
  19. groupby_func = lambda s: (s.task_template_id,
  20. s.start_time,
  21. s.task_type_id)
  22. groupby_iter = groupby(shifts, groupby_func)
  23. shifts_and_count = []
  24. for (keys, grouped_shifts) in groupby_iter:
  25. (task_template, start_time, task_type) = keys
  26. s = list(grouped_shifts)
  27. free_space = len(s)
  28. # Among shifts with at least 5 worker max, shows only shifts
  29. # where there is at least two free spaces
  30. if task_template.worker_nb > 5 and len(s) >= 2:
  31. shifts_and_count.append([free_space, s[0]])
  32. # Show available shifts if there is less than 5 worker max
  33. if task_template.worker_nb <= 5:
  34. shifts_and_count.append([free_space, s[0]])
  35. return request.render(
  36. 'beesdoo_website_shift.shift_template',
  37. {
  38. 'shift_templates': shifts_and_count
  39. }
  40. )
  41. @http.route('/shift_template_regular_worker', auth='public', website=True)
  42. def shift_template_regular_worker(self, **kwargs):
  43. # Get all the task template
  44. template = request.env['beesdoo.shift.template']
  45. task_templates = template.sudo().search(
  46. [],
  47. order="planning_id, day_nb_id, start_time"
  48. )
  49. return request.render(
  50. 'beesdoo_website_shift.task_template',
  51. {
  52. 'task_templates': task_templates,
  53. 'float_to_time': float_to_time
  54. }
  55. )