From b4d9c636f78ab9c16519d2855a2277547b326822 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Tue, 20 Feb 2018 23:55:46 +0100 Subject: [PATCH] [ADD] beesdoo_shift: S0048 temporary exemption --- beesdoo_shift/__openerp__.py | 1 + beesdoo_shift/models/cooperative_status.py | 28 ++++++++++++++++++-- beesdoo_shift/models/planning.py | 5 +++- beesdoo_shift/models/task.py | 2 +- beesdoo_shift/views/cooperative_status.xml | 14 +++++++--- beesdoo_shift/wizard/__init__.py | 3 ++- beesdoo_shift/wizard/temporary_exemption.py | 24 +++++++++++++++++ beesdoo_shift/wizard/temporary_exemption.xml | 21 +++++++++++++++ 8 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 beesdoo_shift/wizard/temporary_exemption.py create mode 100644 beesdoo_shift/wizard/temporary_exemption.xml diff --git a/beesdoo_shift/__openerp__.py b/beesdoo_shift/__openerp__.py index e6f8a71..7ff8d95 100644 --- a/beesdoo_shift/__openerp__.py +++ b/beesdoo_shift/__openerp__.py @@ -34,5 +34,6 @@ "wizard/subscribe.xml", "wizard/extension.xml", "wizard/holiday.xml", + "wizard/temporary_exemption.xml", ], } diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index 6fbb170..218361d 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -63,6 +63,7 @@ class CooperativeStatus(models.Model): ('alert', 'Alerte'), ('extension', 'Extension'), ('suspended', 'Suspended'), + ('exempted', 'Exempted'), ('unsubscribed', 'Unsubscribed')], compute="_compute_status", string="Cooperative Status", store=True) can_shop = fields.Boolean(compute='_compute_status', store=True) @@ -74,12 +75,17 @@ class CooperativeStatus(models.Model): irregular_absence_date = fields.Date() irregular_absence_counter = fields.Integer() #TODO unsubscribe when reach -2 + temporary_exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason') + temporary_exempt_start_date = fields.Date() + temporary_exempt_end_date = fields.Date() + @api.depends('today', 'sr', 'sc', 'holiday_end_time', 'holiday_start_time', 'time_extension', 'alert_start_time', 'extension_start_time', 'unsubscribed', 'irregular_absence_date', - 'irregular_absence_counter') + 'irregular_absence_counter', 'temporary_exempt_start_date', + 'temporary_exempt_end_date') def _compute_status(self): alert_delay = int(self.env['ir.config_parameter'].get_param('alert_delay', 28)) grace_delay = int(self.env['ir.config_parameter'].get_param('default_grace_delay', 10)) @@ -106,6 +112,9 @@ class CooperativeStatus(models.Model): if self.sr < -1 or self.unsubscribed: self.status = 'unsubscribed' self.can_shop = False + elif self.today >= self.temporary_exempt_start_date and self.today <= self.temporary_exempt_end_date: + self.status = 'exempted' + self.can_shop = True #Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined elif not ok and self.alert_start_time and self.extension_start_time and self.today <= add_days_delta(self.extension_start_time, grace_delay): @@ -133,11 +142,13 @@ class CooperativeStatus(models.Model): self.ensure_one() ok = self.sr >= 0 grace_delay = grace_delay + self.time_extension - print add_days_delta(self.extension_start_time, grace_delay) if (not ok and self.irregular_absence_date and self.today > add_days_delta(self.irregular_absence_date, alert_delay * 2)) \ or self.unsubscribed or self.irregular_absence_counter <= -2: self.status = 'unsubscribed' self.can_shop = False + elif self.today >= self.temporary_exempt_start_date and self.today <= self.temporary_exempt_end_date: + self.status = 'exempted' + self.can_shop = True #Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined elif not ok and self.alert_start_time and self.extension_start_time and self.today <= add_days_delta(self.extension_start_time, grace_delay): self.status = 'extension' @@ -246,6 +257,8 @@ class CooperativeStatus(models.Model): irregular = self.search([('status', '!=', 'unsubscribed'), ('working_mode', '=', 'irregular'), ('irregular_start_date', '!=', False)]) today_date = fields.Date.from_string(today) for status in irregular: + if status.status == 'exempted': + continue delta = (today_date - fields.Date.from_string(status.irregular_start_date)).days if delta and delta % 28 == 0 and status not in journal.line_ids: #TODO use system parameter for 28 if status.sr > 0: @@ -333,5 +346,16 @@ class ResPartner(models.Model): 'target': 'new', } + @api.multi + def temporary_exempt(self): + return { + 'name': _('Temporary Exemption'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'beesdoo.shift.temporary_exemption', + 'target': 'new', + } + #TODO access right + vue on res.partner #TODO can_shop : Status can_shop ou extempted ou part C diff --git a/beesdoo_shift/models/planning.py b/beesdoo_shift/models/planning.py index dc8b8b7..fd87ab7 100644 --- a/beesdoo_shift/models/planning.py +++ b/beesdoo_shift/models/planning.py @@ -141,12 +141,15 @@ class TaskTemplate(models.Model): for rec in self: for i in xrange(0, rec.worker_nb): worker_id = rec.worker_ids[i] if len(rec.worker_ids) > i else False - #remove worker in holiday + #remove worker in holiday and temporary exempted if worker_id and worker_id.cooperative_status_ids: status = worker_id.cooperative_status_ids[0] if status.holiday_start_time and status.holiday_end_time and \ status.holiday_start_time <= rec.start_date[:10] and status.holiday_end_time >= rec.end_date[:10]: worker_id = False + if status.temporary_exempt_start_date and status.temporary_exempt_end_date and \ + status.temporary_exempt_start_date <= rec.start_date[:10] and status.temporary_exempt_end_date >= rec.end_date[:10]: + worker_id = False tasks |= tasks.create({ 'name' : "%s %s (%s - %s) [%s]" % (rec.name, rec.day_nb_id.name, float_to_time(rec.start_time), float_to_time(rec.end_time), i), 'task_template_id' : rec.id, diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 6058c2b..39121fc 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -29,7 +29,7 @@ class Task(models.Model): planning_id = fields.Many2one(related='task_template_id.planning_id', store=True) task_type_id = fields.Many2one('beesdoo.shift.type', string="Task Type") worker_id = fields.Many2one('res.partner', track_visibility='onchange', domain=[('eater', '=', 'worker_eater')]) - start_time = fields.Datetime(track_visibility='always') + start_time = fields.Datetime(track_visibility='always', index=True) end_time = fields.Datetime(track_visibility='always') stage_id = fields.Many2one('beesdoo.shift.stage', required=True, track_visibility='onchange', default=lambda self: self.env.ref('beesdoo_shift.open')) super_coop_id = fields.Many2one('res.users', string="Super Cooperative", domain=[('partner_id.super', '=', True)], track_visibility='onchange') diff --git a/beesdoo_shift/views/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml index 39322a6..6273a25 100644 --- a/beesdoo_shift/views/cooperative_status.xml +++ b/beesdoo_shift/views/cooperative_status.xml @@ -29,6 +29,9 @@