From 5be9ee380c055b531e3675e3e4e093231945ffbe Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Sat, 20 Oct 2018 00:04:29 +0200 Subject: [PATCH] [CHANGE] -1 instead of -2 when not attempting a shift, -2 only when alert time is not set, remove alert time only once you reach +1 --- beesdoo_shift/models/cooperative_status.py | 14 ++++++++++---- beesdoo_shift/models/task.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index c73ed96..5e32041 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -212,12 +212,15 @@ class CooperativeStatus(models.Model): self.env['cooperative.status.history'].sudo().create(data) return super(CooperativeStatus, self).write(vals) - def _state_change(self, new_state, old_stage): + def _state_change(self, new_state): self.ensure_one() if new_state == 'alert': self.write({'alert_start_time': self.today, 'extension_start_time': False, 'time_extension': 0}) - if new_state == 'ok': #reset alert start time if back to ok - self.write({'alert_start_time': False, 'extension_start_time': False, 'time_extension': 0}) + if new_state == 'ok': + data = {'extension_start_time': False, 'time_extension': 0} + if self.working_mode != 'irregular': #Don't reset alert time for irregular + data['alert_start_time'] = False + self.write(data) if new_state == 'unsubscribed': self.cooperator_id.sudo().write({'subscribed_shift_ids' : [(5,0,0)]}) #TODO: Add one day othertwise unsubscribed from the shift you were absent @@ -249,7 +252,7 @@ class CooperativeStatus(models.Model): 'user_id': self.env.context.get('real_uid', self.env.uid), } self.env['cooperative.status.history'].sudo().create(data) - rec._state_change(vals['status'], old_status_per_id[rec.id]['status']) + rec._state_change(vals['status']) return super(CooperativeStatus, self)._write(vals) _sql_constraints = [ @@ -292,6 +295,9 @@ class CooperativeStatus(models.Model): if delta and delta % PERIOD == 0 and status not in journal.line_ids: if status.sr > 0: status.sr -= 1 + status.alert_start_time = False + elif status.alert_start_time: + status.sr -= 1 else: status.sr -= 2 journal.line_ids |= status diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 51d99c6..91345b4 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -168,7 +168,7 @@ class Task(models.Model): data['irregular_absence_date'] = False data['irregular_absence_counter'] = 1 if status.irregular_absence_counter < 0 else 0 if new_stage == ABSENT or new_stage == EXCUSED: - data['sr'] = -2 + data['sr'] = -1 data['irregular_absence_date'] = self.start_time[:10] data['irregular_absence_counter'] = -1