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. 3
      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

3
beesdoo_worker_status/models/__init__.py

@ -1 +1,2 @@
from . import cooperative_status
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 # # Status Change implementation #
##################################### #####################################
def _set_regular_status(self, grace_delay, alert_delay):
def _get_regular_status(self):
self.ensure_one() 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 ok = self.sr >= 0 and self.sc >= 0
grace_delay = grace_delay + self.time_extension grace_delay = grace_delay + self.time_extension
if (self.sr + self.sc) <= counter_unsubscribe or self.unsubscribed: if (self.sr + self.sc) <= counter_unsubscribe or self.unsubscribed:
return '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 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: if not self.temporary_exempt_end_date or self.today <= self.temporary_exempt_end_date:
return 'exempted' 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): 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' 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): 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): elif ok or (not self.alert_start_time and self.sr >= 0):
return 'ok' 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() 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 ok = self.sr >= 0
grace_delay = grace_delay + self.time_extension grace_delay = grace_delay + self.time_extension
if self.sr <= counter_unsubscribe or self.unsubscribed: if self.sr <= counter_unsubscribe or self.unsubscribed:
return '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: 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: if not self.temporary_exempt_end_date or self.today <= self.temporary_exempt_end_date:
return 'exempted' 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): 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' 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): 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 from odoo.exceptions import UserError, ValidationError
class Task(models.Model): class Task(models.Model):
_inherit = 'beesdoo.shift.shift' _inherit = 'beesdoo.shift.shift'
@ -23,7 +22,7 @@ class Task(models.Model):
("cancel","Cancelled") ("cancel","Cancelled")
] ]
def _get_color_mapping(state):
def _get_color_mapping(self, state):
return { return {
"draft": 0, "draft": 0,
"open": 1, "open": 1,
@ -34,9 +33,10 @@ class Task(models.Model):
"cancel": 9, "cancel": 9,
}[state] }[state]
def _get_final_state():
def _get_final_state(self):
return ["done", "absent_2", "absent_1", "absent_0"] return ["done", "absent_2", "absent_1", "absent_0"]
state = fields.Selection(selection=_get_selection_status)
############################################## ##############################################
# Change counter when state change # # Change counter when state change #
@ -45,7 +45,7 @@ class Task(models.Model):
data = {} data = {}
if self.worker_id.working_mode == 'regular': 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] status = self.worker_id.cooperative_status_ids[0]
else: else:
status = self.replaced_id.cooperative_status_ids[0] status = self.replaced_id.cooperative_status_ids[0]
@ -78,4 +78,4 @@ class Task(models.Model):
data['sr'] = -1 data['sr'] = -1
data['irregular_absence_date'] = self.start_time.date() data['irregular_absence_date'] = self.start_time.date()
data['irregular_absence_counter'] = -1 data['irregular_absence_counter'] = -1
return data
return data, status
Loading…
Cancel
Save