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.

56 lines
2.2 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, s.start_time, s.task_type_id)
  20. groupby_iter = groupby(shifts, groupby_func)
  21. shifts_and_count = []
  22. for (keys, grouped_shifts) in groupby_iter:
  23. (task_template, _, _) = keys
  24. s = list(grouped_shifts)
  25. free_space = len(s)
  26. # Among shifts with at least 5 worker max, shows only shifts
  27. # where there is at least two free spaces
  28. if task_template.worker_nb > 5 and free_space >= 2:
  29. shifts_and_count.append([free_space, s[0]])
  30. # Show available shifts if there is less than 5 worker max
  31. if task_template.worker_nb <= 5:
  32. shifts_and_count.append([free_space, s[0]])
  33. return request.render('beesdoo_website_shift.shift_template',
  34. {
  35. 'shift_templates': shifts_and_count
  36. }
  37. )
  38. @http.route('/shift_template_regular_worker', auth='public', website=True)
  39. def shift_template_regular_worker(self, **kwargs):
  40. # Get all the task template
  41. template = request.env['beesdoo.shift.template']
  42. task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time")
  43. return request.render('beesdoo_website_shift.task_template',
  44. {
  45. 'task_templates': task_templates,
  46. 'float_to_time': float_to_time
  47. }
  48. )