From 9365bfb69a49891e49233abb86a017241b8c2019 Mon Sep 17 00:00:00 2001 From: Elouan Le Bars Date: Mon, 16 Sep 2019 18:26:38 +0200 Subject: [PATCH] [FIX] beesdoo_shift : fixed datetime issues coming from migration to 12.0 --- beesdoo_shift/models/cooperative_status.py | 11 ++++------- beesdoo_shift/models/planning.py | 5 ++--- beesdoo_shift/models/task.py | 2 +- beesdoo_shift/wizard/extension.py | 4 +--- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index 6ff5956..9f4e6df 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -10,8 +10,8 @@ PERIOD = 28 # TODO: use system parameter def add_days_delta(date_from, days_delta): if not date_from: return date_from - next_date = fields.Date.from_string(date_from) + timedelta(days=days_delta) - return fields.Date.to_string(next_date) + next_date = date_from + timedelta(days=days_delta) + return next_date class ExemptReason(models.Model): _name = 'cooperative.exempt.reason' @@ -203,9 +203,7 @@ class CooperativeStatus(models.Model): This does not take holiday and other status into account. """ today = today or fields.Date.today() - today_dt = fields.Date.from_string(today) - irregular_start_dt = fields.Date.from_string(irregular_start_date) - delta = (today_dt - irregular_start_dt).days + delta = (today - irregular_start_date).days return add_days_delta(today, PERIOD - (delta % PERIOD)) def _set_regular_status(self, grace_delay, alert_delay): @@ -380,11 +378,10 @@ class CooperativeStatus(models.Model): '|', ('holiday_start_time', '>', today), ('holiday_end_time', '<', today), ] irregular = self.search(domain) - today_date = fields.Date.from_string(today) for status in irregular: if status.status == 'exempted': continue - delta = (today_date - fields.Date.from_string(status.irregular_start_date)).days + delta = (today - status.irregular_start_date).days if delta and delta % PERIOD == 0 and status not in journal.line_ids: if status.sr > 0: status.sr -= 1 diff --git a/beesdoo_shift/models/planning.py b/beesdoo_shift/models/planning.py index a2ac71f..301b00d 100644 --- a/beesdoo_shift/models/planning.py +++ b/beesdoo_shift/models/planning.py @@ -154,12 +154,11 @@ class TaskTemplate(models.Model): #remove worker in holiday and temporary exempted if worker_id and worker_id.cooperative_status_ids: status = worker_id.cooperative_status_ids[0] - import pdb; pdb.set_trace() if status.holiday_start_time and status.holiday_end_time and \ - status.holiday_start_time <= rec.start_date and status.holiday_end_time >= rec.end_date: + status.holiday_start_time <= rec.start_date.date() and status.holiday_end_time >= rec.end_date.date(): worker_id = False if status.temporary_exempt_start_date and status.temporary_exempt_end_date and \ - status.temporary_exempt_start_date <= rec.start_date and status.temporary_exempt_end_date >= rec.end_date: + status.temporary_exempt_start_date <= rec.start_date.date() and status.temporary_exempt_end_date >= rec.end_date.date(): worker_id = False tasks |= tasks.create({ 'name' : "%s %s (%s - %s) [%s]" % (rec.name, rec.day_nb_id.name, float_to_time(rec.start_time), float_to_time(rec.end_time), i), diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index ce2742b..c854140 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -229,7 +229,7 @@ class Task(models.Model): data['irregular_absence_counter'] = 1 if status.irregular_absence_counter < 0 else 0 if new_stage == ABSENT or new_stage == EXCUSED: data['sr'] = -1 - data['irregular_absence_date'] = self.start_time[:10] + data['irregular_absence_date'] = self.start_time data['irregular_absence_counter'] = -1 else: diff --git a/beesdoo_shift/wizard/extension.py b/beesdoo_shift/wizard/extension.py index 39856bb..bb20eea 100644 --- a/beesdoo_shift/wizard/extension.py +++ b/beesdoo_shift/wizard/extension.py @@ -26,9 +26,7 @@ class Subscribe(models.TransientModel): status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)]) if not status_id.extension_start_time: raise UserError(_('You should not make a manual extension when the grace delay has not been triggered yet')) - extension_date = fields.Date.from_string(status_id.extension_start_time) - today = fields.Date.from_string(status_id.today) - today_delay = (today - extension_date).days - grace_delay + today_delay = (status_id.today - status_id.extension_start_time).days - grace_delay if today_delay < 0: raise UserError(_('You should not start a manual extension during the grace delay')) status_id.sudo().write({'time_extension': self.extension_days + today_delay})