From fd2839985cb9c5c23e0f75b34f1ca53d499c6b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Thu, 7 Dec 2017 11:31:49 +0100 Subject: [PATCH] [ADD] website_shift: Irregular personal work page Add personal shift page for irregular worker that allows you to subscribe to a shift. --- beesdoo_website_shift/controllers/main.py | 58 ++- .../views/shift_website_templates.xml | 369 ++++++++++++++---- 2 files changed, 346 insertions(+), 81 deletions(-) diff --git a/beesdoo_website_shift/controllers/main.py b/beesdoo_website_shift/controllers/main.py index 55b5757..9b2e4d6 100644 --- a/beesdoo_website_shift/controllers/main.py +++ b/beesdoo_website_shift/controllers/main.py @@ -8,8 +8,36 @@ from openerp.addons.beesdoo_shift.models.planning import float_to_time class WebsiteShiftController(http.Controller): - @http.route('/shift_irregular_worker', auth='public', website=True) + @http.route('/shift', auth='user', website=True) + def shift(self, **kwargs): + cur_user = request.env['res.users'].browse(request.uid) + working_mode = cur_user.partner_id.working_mode + if working_mode == 'irregular': + return self.shift_irregular_worker() + if working_mode == 'regular': + return self.shift_template_regular_worker() + + return request.render( + 'beesdoo_website_shift.shift', + { + 'user': cur_user, + } + ) + + @http.route('/shift//subscribe', auth='user', website=True) + def subscribe_to_shift(self, shift=None, **kwargs): + # Get current user + cur_user = request.env['res.users'].browse(request.uid) + if (cur_user.partner_id.working_mode == 'irregular' + and shift + and not shift.worker_id): + shift.worker_id = cur_user.partner_id + return request.redirect(kwargs['nexturl']) + def shift_irregular_worker(self, **kwargs): + # Get current user + cur_user = request.env['res.users'].browse(request.uid) + # Get all the shifts in the future with no worker now = datetime.now() shifts = request.env['beesdoo.shift.shift'].sudo().search( @@ -18,6 +46,13 @@ class WebsiteShiftController(http.Controller): order="start_time, task_template_id, task_type_id", ) + # Get shifts where user is subscribed + subscribed_shifts = request.env['beesdoo.shift.shift'].sudo().search( + [('start_time', '>', now.strftime("%Y-%m-%d %H:%M:%S")), + ('worker_id', '=', cur_user.partner_id.id)], + order="start_time, task_template_id, task_type_id", + ) + # Get config irregular_shift_limit = int(request.env['ir.config_parameter'].get_param( 'beesdoo_website_shift.irregular_shift_limit')) @@ -31,24 +66,35 @@ class WebsiteShiftController(http.Controller): groupby_func = lambda s: (s.task_template_id, s.start_time, s.task_type_id) groupby_iter = groupby(shifts, groupby_func) - shifts_and_count = [] + shifts_count_subscribed = [] nb_displayed_shift = 0 # Number of shift displayed for (keys, grouped_shifts) in groupby_iter: - (task_template, _, _) = keys + (task_template, start_time, task_type) = keys nb_displayed_shift = nb_displayed_shift + 1 s = list(grouped_shifts) + # Compute available space free_space = len(s) + # Is the current user subscribed to this task_template + is_subscribed = any( + (sub_shift.task_template_id == task_template and + sub_shift.start_time == start_time and + sub_shift.task_type_id == task_type) + for sub_shift in subscribed_shifts) if free_space >= task_template.worker_nb * hide_rule: - shifts_and_count.append([free_space, s[0]]) + shifts_count_subscribed.append([s[0], free_space, is_subscribed]) # Stop showing shifts if the limit is reached if irregular_shift_limit > 0 and nb_displayed_shift >= irregular_shift_limit: break return request.render( - 'beesdoo_website_shift.shift_template', + 'beesdoo_website_shift.irregular_worker', { - 'shift_templates': shifts_and_count, + 'partner': cur_user.partner_id, + 'status': cur_user.partner_id.cooperative_status_ids, + 'shift_templates': shifts_count_subscribed, 'highlight_rule': highlight_rule, + 'nexturl': '/shift', + 'subscribed_shifts': subscribed_shifts, } ) diff --git a/beesdoo_website_shift/views/shift_website_templates.xml b/beesdoo_website_shift/views/shift_website_templates.xml index 1d507e5..4d4fd8d 100644 --- a/beesdoo_website_shift/views/shift_website_templates.xml +++ b/beesdoo_website_shift/views/shift_website_templates.xml @@ -3,19 +3,23 @@ - Shifts Irregular - /shift_irregular_worker + Shifts + /shift 50 - - Shifts Regular - /shift_template_regular_worker - - 51 - + + + - +