From f0062bc741b4fe4a0bc1f1b9ce922d0c25e1d01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Tue, 9 Jan 2018 16:39:41 +0100 Subject: [PATCH] [ADD] website_shift: Past shifts on personal page Add a list of the previous shifts for a worker. --- beesdoo_website_shift/controllers/main.py | 36 ++++++++ .../data/res_config_data.xml | 8 ++ beesdoo_website_shift/models/res_config.py | 25 ++++++ .../views/my_shift_website_templates.xml | 89 +++++++++++++++++++ .../views/res_config_views.xml | 36 ++++++++ 5 files changed, 194 insertions(+) diff --git a/beesdoo_website_shift/controllers/main.py b/beesdoo_website_shift/controllers/main.py index f95e8a8..9b845cd 100644 --- a/beesdoo_website_shift/controllers/main.py +++ b/beesdoo_website_shift/controllers/main.py @@ -133,6 +133,7 @@ class WebsiteShiftController(http.Controller): template_context.update(self.my_shift_worker_status()) template_context.update(self.my_shift_next_shifts()) + template_context.update(self.my_shift_past_shifts()) template_context.update(self.available_shift_irregular_worker( irregular_enable_sign_up, nexturl )) @@ -163,6 +164,7 @@ class WebsiteShiftController(http.Controller): template_context.update(self.my_shift_worker_status()) template_context.update(self.my_shift_next_shifts()) + template_context.update(self.my_shift_past_shifts()) template_context.update( { 'task_templates': task_templates, @@ -259,6 +261,40 @@ class WebsiteShiftController(http.Controller): 'subscribed_shifts': subscribed_shifts, } + def my_shift_past_shifts(self): + """ + Return template variables for 'beesdoo_website_shift.my_shift_past_shifts' template + """ + # Get current user + cur_user = request.env['res.users'].browse(request.uid) + # Get config + past_shift_limit = 0 + if self.is_user_irregular(): + past_shift_limit = int(request.env['ir.config_parameter'].get_param( + 'beesdoo_website_shift.irregular_past_shift_limit')) + if self.is_user_regular(): + past_shift_limit = int(request.env['ir.config_parameter'].get_param( + 'beesdoo_website_shift.regular_past_shift_limit')) + # Get shifts where user was subscribed + now = datetime.now() + if past_shift_limit > 0: + past_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", + limit=past_shift_limit, + ) + else: + past_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", + ) + + return { + 'past_shifts': past_shifts, + } + def my_shift_worker_status(self): """ Return template variables for 'beesdoo_website_shift.my_shift_worker_status_*' template diff --git a/beesdoo_website_shift/data/res_config_data.xml b/beesdoo_website_shift/data/res_config_data.xml index 1defe4f..44f373f 100644 --- a/beesdoo_website_shift/data/res_config_data.xml +++ b/beesdoo_website_shift/data/res_config_data.xml @@ -21,5 +21,13 @@ beesdoo_website_shift.irregular_enable_sign_up True + + beesdoo_website_shift.irregular_past_shift_limit + 10 + + + beesdoo_website_shift.regular_past_shift_limit + 10 + diff --git a/beesdoo_website_shift/models/res_config.py b/beesdoo_website_shift/models/res_config.py index 8cf3a7a..c4bbf8e 100644 --- a/beesdoo_website_shift/models/res_config.py +++ b/beesdoo_website_shift/models/res_config.py @@ -11,6 +11,8 @@ PARAMS = [ ('highlight_rule', 'beesdoo_website_shift.highlight_rule'), ('hide_rule', 'beesdoo_website_shift.hide_rule'), ('irregular_enable_sign_up', 'beesdoo_website_shift.irregular_enable_sign_up'), + ('irregular_past_shift_limit', 'beesdoo_website_shift.irregular_past_shift_limit'), + ('regular_past_shift_limit', 'beesdoo_website_shift.regular_past_shift_limit'), ] @@ -19,6 +21,7 @@ class WebsiteShiftConfigSettings(models.TransientModel): _name = 'beesdoo.website.shift.config.settings' _inherit = 'res.config.settings' + # Irregular worker settings irregular_shift_limit = fields.Integer( help="Maximum shift that will be shown" ) @@ -31,6 +34,14 @@ class WebsiteShiftConfigSettings(models.TransientModel): irregular_enable_sign_up = fields.Boolean( help="Enable shift sign up for irregular worker" ) + irregular_past_shift_limit = fields.Integer( + help="Maximum past shift that will be shown for irregular worker" + ) + + # Regular worker settings + regular_past_shift_limit = fields.Integer( + help="Maximum past shift that will be shown for regular worker" + ) @api.multi def set_params(self): @@ -65,3 +76,17 @@ class WebsiteShiftConfigSettings(models.TransientModel): 'irregular_enable_sign_up': literal_eval(self.env['ir.config_parameter'].get_param( 'beesdoo_website_shift.irregular_enable_sign_up')) } + + @api.multi + def get_default_irregular_past_shift_limit(self): + return { + 'irregular_past_shift_limit': int(self.env['ir.config_parameter'].get_param( + 'beesdoo_website_shift.irregular_past_shift_limit')) + } + + @api.multi + def get_default_regular_past_shift_limit(self): + return { + 'regular_past_shift_limit': int(self.env['ir.config_parameter'].get_param( + 'beesdoo_website_shift.regular_past_shift_limit')) + } diff --git a/beesdoo_website_shift/views/my_shift_website_templates.xml b/beesdoo_website_shift/views/my_shift_website_templates.xml index 80337ab..da8d58d 100644 --- a/beesdoo_website_shift/views/my_shift_website_templates.xml +++ b/beesdoo_website_shift/views/my_shift_website_templates.xml @@ -173,6 +173,91 @@ + +