Browse Source

[FIX] beesdoo_shift : fixed datetime issues coming from migration to 12.0

pull/105/head
Elouan Le Bars 5 years ago
parent
commit
9365bfb69a
  1. 11
      beesdoo_shift/models/cooperative_status.py
  2. 5
      beesdoo_shift/models/planning.py
  3. 2
      beesdoo_shift/models/task.py
  4. 4
      beesdoo_shift/wizard/extension.py

11
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

5
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),

2
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:

4
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})
Loading…
Cancel
Save