Browse Source

[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

pull/56/head v1.2-2018-12-01
Thibault Francois 6 years ago
parent
commit
f7084b3873
  1. 14
      beesdoo_shift/models/cooperative_status.py
  2. 2
      beesdoo_shift/models/task.py

14
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

2
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

Loading…
Cancel
Save