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.

40 lines
1.5 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. shifts_and_count = []
  18. for _, val in groupby(shifts, lambda s: s.task_template_id):
  19. s = [v for v in val]
  20. shifts_and_count.append([len(s), s[0]])
  21. return request.render('beesdoo_website_shift.shift_template',
  22. {'shift_templates': shifts_and_count}
  23. )
  24. @http.route('/shift_template_regular_worker', auth='public', website=True)
  25. def shift_template_regular_worker(self, **kwargs):
  26. # Get all the task template
  27. template = request.env['beesdoo.shift.template']
  28. task_templates = template.sudo().search([], order="planning_id, day_nb_id, start_time")
  29. return request.render('beesdoo_website_shift.task_template',
  30. {
  31. 'task_templates': task_templates,
  32. 'float_to_time': float_to_time
  33. }
  34. )