Browse Source

[FIX] b_worker_status

Fix bug reported in 9.0 on the computation of nextcoundown.
Fix missing add_days_delta function.
Fix missing today var.
pull/133/head
Rémy Taymans 5 years ago
parent
commit
cfe1b117b0
  1. 2
      beesdoo_shift/models/cooperative_status.py
  2. 52
      beesdoo_worker_status/models/cooperative_status.py

2
beesdoo_shift/models/cooperative_status.py

@ -191,7 +191,7 @@ class CooperativeStatus(models.Model):
if not journal: if not journal:
journal = self.env['beesdoo.shift.journal'].create({'date': today}) journal = self.env['beesdoo.shift.journal'].create({'date': today})
domain = self._get_irregular_worker_domain()
domain = self._get_irregular_worker_domain(today=today)
irregular = self.search(domain) irregular = self.search(domain)
for status in irregular: for status in irregular:
delta = (today - status.irregular_start_date).days delta = (today - status.irregular_start_date).days

52
beesdoo_worker_status/models/cooperative_status.py

@ -1,9 +1,11 @@
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.addons.beesdoo_shift.models.cooperative_status import add_days_delta
from odoo.exceptions import ValidationError, UserError from odoo.exceptions import ValidationError, UserError
from datetime import timedelta, datetime from datetime import timedelta, datetime
import logging import logging
class CooperativeStatus(models.Model): class CooperativeStatus(models.Model):
_inherit = 'cooperative.status' _inherit = 'cooperative.status'
_period = 28 _period = 28
@ -17,7 +19,6 @@ class CooperativeStatus(models.Model):
future_alert_date = fields.Date(compute='_compute_future_alert_date') future_alert_date = fields.Date(compute='_compute_future_alert_date')
next_countdown_date = fields.Date(compute='_compute_next_countdown_date') next_countdown_date = fields.Date(compute='_compute_next_countdown_date')
@api.depends('today', 'irregular_start_date', 'sr', 'holiday_start_time', @api.depends('today', 'irregular_start_date', 'sr', 'holiday_start_time',
'holiday_end_time', 'temporary_exempt_start_date', 'holiday_end_time', 'temporary_exempt_start_date',
'temporary_exempt_end_date') 'temporary_exempt_end_date')
@ -42,21 +43,28 @@ class CooperativeStatus(models.Model):
counter = rec.sr counter = rec.sr
# Simulate the countdown # Simulate the countdown
while counter > 0: while counter > 0:
date = add_days_delta(date, 1)
date = self._next_countdown_date(rec.irregular_start_date,
date)
date = self._next_countdown_date(
rec.irregular_start_date, date
)
# Check holidays # Check holidays
if (rec.holiday_start_time and rec.holiday_end_time
if (
rec.holiday_start_time and rec.holiday_end_time
and date >= rec.holiday_start_time and date >= rec.holiday_start_time
and date <= rec.holiday_end_time):
and date <= rec.holiday_end_time
):
date = add_days_delta(date, 1)
continue continue
# Check temporary exemption # Check temporary exemption
elif (rec.temporary_exempt_start_date
if (
rec.temporary_exempt_start_date
and rec.temporary_exempt_end_date and rec.temporary_exempt_end_date
and date >= rec.temporary_exempt_start_date and date >= rec.temporary_exempt_start_date
and date <= rec.temporary_exempt_end_date):
and date <= rec.temporary_exempt_end_date
):
date = add_days_delta(date, 1)
continue continue
else:
# Otherwise
date = add_days_delta(date, 1)
counter -= 1 counter -= 1
rec.future_alert_date = self._next_countdown_date( rec.future_alert_date = self._next_countdown_date(
rec.irregular_start_date, date rec.irregular_start_date, date
@ -87,25 +95,30 @@ class CooperativeStatus(models.Model):
date = rec.today date = rec.today
next_countdown_date = False next_countdown_date = False
while not next_countdown_date: while not next_countdown_date:
date = self._next_countdown_date(rec.irregular_start_date, date)
date = self._next_countdown_date(
rec.irregular_start_date, date
)
# Check holidays # Check holidays
if (rec.holiday_start_time and rec.holiday_end_time
if (
rec.holiday_start_time and rec.holiday_end_time
and date >= rec.holiday_start_time and date >= rec.holiday_start_time
and date <= rec.holiday_end_time):
and date <= rec.holiday_end_time
):
date = add_days_delta(date, 1) date = add_days_delta(date, 1)
continue continue
# Check temporary exemption # Check temporary exemption
elif (rec.temporary_exempt_start_date
if (
rec.temporary_exempt_start_date
and rec.temporary_exempt_end_date and rec.temporary_exempt_end_date
and date >= rec.temporary_exempt_start_date and date >= rec.temporary_exempt_start_date
and date <= rec.temporary_exempt_end_date):
and date <= rec.temporary_exempt_end_date
):
date = add_days_delta(date, 1) date = add_days_delta(date, 1)
continue continue
else:
# Otherwise
next_countdown_date = date next_countdown_date = date
rec.next_countdown_date = next_countdown_date rec.next_countdown_date = next_countdown_date
##################################### #####################################
# Status Change implementation # # Status Change implementation #
##################################### #####################################
@ -210,7 +223,8 @@ class CooperativeStatus(models.Model):
###### Irregular Cron implementation ########## ###### Irregular Cron implementation ##########
############################################### ###############################################
def _get_irregular_worker_domain(self):
def _get_irregular_worker_domain(self, **kwargs):
today = kwargs.get("today") or self.today
return ['&', return ['&',
'&', '&',
'&', '&',
@ -242,9 +256,9 @@ class CooperativeStatus(models.Model):
today = today or fields.Date.today() today = today or fields.Date.today()
delta = (today - irregular_start_date).days delta = (today - irregular_start_date).days
if not delta % PERIOD:
if not delta % self._period:
return today return today
return add_days_delta(today, PERIOD - (delta % PERIOD))
return add_days_delta(today, self._period - (delta % self._period))
class ResPartner(models.Model): class ResPartner(models.Model):

Loading…
Cancel
Save