Browse Source

[FIX] b_worker_status

pull/133/head
Rémy Taymans 5 years ago
parent
commit
d860bab58e
  1. 1
      beesdoo_worker_status/__init__.py
  2. 1
      beesdoo_worker_status/models/__init__.py
  3. 20
      beesdoo_worker_status/models/cooperative_status.py
  4. 10
      beesdoo_worker_status/models/task.py

1
beesdoo_worker_status/__init__.py

@ -0,0 +1 @@
from . import models

1
beesdoo_worker_status/models/__init__.py

@ -1 +1,2 @@
from . import cooperative_status
from . import task

20
beesdoo_worker_status/models/cooperative_status.py

@ -122,20 +122,22 @@ class CooperativeStatus(models.Model):
#####################################
# Status Change implementation #
#####################################
def _set_regular_status(self, grace_delay, alert_delay):
def _get_regular_status(self):
self.ensure_one()
counter_unsubscribe = int(self.env['ir.config_parameter'].get_param('regular_counter_to_unsubscribe', -4))
counter_unsubscribe = int(self.env['ir.config_parameter'].sudo().get_param('regular_counter_to_unsubscribe', -4))
alert_delay = int(self.env['ir.config_parameter'].sudo().get_param('alert_delay', 28))
grace_delay = int(self.env['ir.config_parameter'].sudo().get_param('default_grace_delay', 10))
ok = self.sr >= 0 and self.sc >= 0
grace_delay = grace_delay + self.time_extension
if (self.sr + self.sc) <= counter_unsubscribe or self.unsubscribed:
return 'unsubscribed'
#Check if exempted. Exempt end date is not required.
# Check if exempted. Exempt end date is not required.
if self.temporary_exempt_start_date and self.today >= self.temporary_exempt_start_date:
if not self.temporary_exempt_end_date or self.today <= self.temporary_exempt_end_date:
return 'exempted'
#Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined
# Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined
if not ok and self.alert_start_time and self.extension_start_time and self.today <= add_days_delta(self.extension_start_time, grace_delay):
return 'extension'
if not ok and self.alert_start_time and self.extension_start_time and self.today > add_days_delta(self.extension_start_time, grace_delay):
@ -156,18 +158,20 @@ class CooperativeStatus(models.Model):
elif ok or (not self.alert_start_time and self.sr >= 0):
return 'ok'
def _set_irregular_status(self, grace_delay, alert_delay):
counter_unsubscribe = int(self.env['ir.config_parameter'].get_param('irregular_counter_to_unsubscribe', -3))
def _get_irregular_status(self):
self.ensure_one()
counter_unsubscribe = int(self.env['ir.config_parameter'].sudo().get_param('irregular_counter_to_unsubscribe', -3))
alert_delay = int(self.env['ir.config_parameter'].sudo().get_param('alert_delay', 28))
grace_delay = int(self.env['ir.config_parameter'].sudo().get_param('default_grace_delay', 10))
ok = self.sr >= 0
grace_delay = grace_delay + self.time_extension
if self.sr <= counter_unsubscribe or self.unsubscribed:
return 'unsubscribed'
#Check if exempted. Exempt end date is not required.
# Check if exempted. Exempt end date is not required.
elif self.temporary_exempt_start_date and self.today >= self.temporary_exempt_start_date:
if not self.temporary_exempt_end_date or self.today <= self.temporary_exempt_end_date:
return 'exempted'
#Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined
# 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):
return 'extension'
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):

10
beesdoo_worker_status/models/task.py

@ -5,7 +5,6 @@ from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
class Task(models.Model):
_inherit = 'beesdoo.shift.shift'
@ -23,7 +22,7 @@ class Task(models.Model):
("cancel","Cancelled")
]
def _get_color_mapping(state):
def _get_color_mapping(self, state):
return {
"draft": 0,
"open": 1,
@ -34,9 +33,10 @@ class Task(models.Model):
"cancel": 9,
}[state]
def _get_final_state():
def _get_final_state(self):
return ["done", "absent_2", "absent_1", "absent_0"]
state = fields.Selection(selection=_get_selection_status)
##############################################
# Change counter when state change #
@ -45,7 +45,7 @@ class Task(models.Model):
data = {}
if self.worker_id.working_mode == 'regular':
if not self.replaced_id: #No replacement case
if not self.replaced_id: # No replacement case
status = self.worker_id.cooperative_status_ids[0]
else:
status = self.replaced_id.cooperative_status_ids[0]
@ -78,4 +78,4 @@ class Task(models.Model):
data['sr'] = -1
data['irregular_absence_date'] = self.start_time.date()
data['irregular_absence_counter'] = -1
return data
return data, status
Loading…
Cancel
Save