def _get_regular_status(self): self.ensure_one() 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 # check `holiday` if (self.holiday_start_time and self.holiday_end_time and self.today >= self.holiday_start_time and self.today <= self.holiday_end_time): return "holiday" # check `exempted`. # Exempt end date is not required. elif ( # Start and end are defined self.temporary_exempt_start_date and self.temporary_exempt_end_date and self.today >= self.temporary_exempt_start_date and self.today <= self.temporary_exempt_end_date) or ( # Only start is defined self.temporary_exempt_start_date and not self.temporary_exempt_end_date and self.today >= self.temporary_exempt_start_date): return "exempted" # check `extension` # 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" # check `unsubscribed` elif (self.sr + self.sc) <= counter_unsubscribe or self.unsubscribed: return "unsubscribed" # check `suspended` 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)) or ( not ok and self.alert_start_time and self.today > add_days_delta(self.alert_start_time, alert_delay)): return "suspended" # check `alert` elif (self.sr < 0) or (not ok and self.alert_start_time): return "alert" # check `ok` elif ok or (not self.alert_start_time and self.sr >= 0): return "ok"
def _compute_future_alert_date(self): """Compute date before which the worker is up to date""" for rec in self: # Only for irregular worker if (rec.working_mode != "irregular" and not rec.irregular_start_date): rec.future_alert_date = False # Alert start time already set elif rec.alert_start_time: rec.future_alert_date = False # Holidays are not set properly elif bool(rec.holiday_start_time) != bool(rec.holiday_end_time): rec.future_alert_date = False # Exemption have not a start and end time elif bool(rec.temporary_exempt_start_date) != bool( rec.temporary_exempt_end_date): rec.future_alert_date = False else: date = rec.today counter = rec.sr # Simulate the countdown while counter > 0: date = self._next_countdown_date(rec.irregular_start_date, date) # Check holidays if (rec.holiday_start_time and rec.holiday_end_time and date >= rec.holiday_start_time and date <= rec.holiday_end_time): date = add_days_delta(date, 1) continue # Check temporary exemption if (rec.temporary_exempt_start_date and rec.temporary_exempt_end_date and date >= rec.temporary_exempt_start_date and date <= rec.temporary_exempt_end_date): date = add_days_delta(date, 1) continue # Otherwise date = add_days_delta(date, 1) counter -= 1 rec.future_alert_date = self._next_countdown_date( rec.irregular_start_date, date)
def _next_countdown_date(self, irregular_start_date, today): """ Return the next countdown date given irregular_start_date and today dates. This does not take holiday and other status into account. """ delta = (today - irregular_start_date).days if not delta % self._period: return today return add_days_delta(today, self._period - (delta % self._period))
def _compute_next_countdown_date(self): """ Compute the following countdown date. This date is the date when the worker will see his counter changed du to the cron. This date is like the birthday date of the worker that occurred each PERIOD. """ for rec in self: # Only for irregular worker if (rec.working_mode != "irregular" and not rec.irregular_start_date): rec.next_countdown_date = False # Holidays are not set properly elif bool(rec.holiday_start_time) != bool(rec.holiday_end_time): rec.next_countdown_date = False # Exemption have not a start and end time elif bool(rec.temporary_exempt_start_date) != bool( rec.temporary_exempt_end_date): rec.next_countdown_date = False else: date = rec.today next_countdown_date = False while not next_countdown_date: date = self._next_countdown_date(rec.irregular_start_date, date) # Check holidays if (rec.holiday_start_time and rec.holiday_end_time and date >= rec.holiday_start_time and date <= rec.holiday_end_time): date = add_days_delta(date, 1) continue # Check temporary exemption if (rec.temporary_exempt_start_date and rec.temporary_exempt_end_date and date >= rec.temporary_exempt_start_date and date <= rec.temporary_exempt_end_date): date = add_days_delta(date, 1) continue # Otherwise next_countdown_date = date rec.next_countdown_date = next_countdown_date