From 71f273c3a96a9d999d77121579d92c83dcf02e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Sat, 24 Mar 2018 11:32:59 +0100 Subject: [PATCH] [ADD] beesdoo_shift: Future alert date --- beesdoo_shift/models/cooperative_status.py | 16 +++++++++++++++- beesdoo_shift/views/cooperative_status.xml | 9 +++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index c5045e5..05dd4eb 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -7,6 +7,7 @@ import logging from openerp.osv.fields import related _logger = logging.getLogger(__name__) +PERIOD = 28 # TODO: use system parameter def add_days_delta(date_from, days_delta): if not date_from: @@ -76,6 +77,7 @@ class CooperativeStatus(models.Model): irregular_start_date = fields.Date() #TODO migration script irregular_absence_date = fields.Date() irregular_absence_counter = fields.Integer() #TODO unsubscribe when reach -2 + future_alert_date = fields.Date(compute='_compute_future_alert_date') temporary_exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason') temporary_exempt_start_date = fields.Date() @@ -110,6 +112,18 @@ class CooperativeStatus(models.Model): rec.status = 'ok' rec.can_shop = True + @api.depends('today', 'irregular_start_date', 'sr') + def _compute_future_alert_date(self): + """Compute date before which the worker is up to date""" + for rec in self: + future_alert_date = False + if not rec.alert_start_time and rec.irregular_start_date: + today_date = fields.Date.from_string(rec.today) + delta = (today_date - fields.Date.from_string(rec.irregular_start_date)).days + future_alert_date = today_date + timedelta(days=(rec.sr + 1) * PERIOD - delta % PERIOD) + future_alert_date = future_alert_date.strftime('%Y-%m-%d') + rec.future_alert_date = future_alert_date + def _set_regular_status(self, grace_delay, alert_delay): self.ensure_one() ok = self.sr >= 0 and self.sc >= 0 @@ -266,7 +280,7 @@ class CooperativeStatus(models.Model): if status.status == 'exempted': continue delta = (today_date - fields.Date.from_string(status.irregular_start_date)).days - if delta and delta % 28 == 0 and status not in journal.line_ids: #TODO use system parameter for 28 + if delta and delta % PERIOD == 0 and status not in journal.line_ids: if status.sr > 0: status.sr -= 1 else: diff --git a/beesdoo_shift/views/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml index 1327593..dbf8dc3 100644 --- a/beesdoo_shift/views/cooperative_status.xml +++ b/beesdoo_shift/views/cooperative_status.xml @@ -70,7 +70,7 @@ - + @@ -84,6 +84,7 @@ + @@ -132,7 +133,7 @@ - + Journal Form View beesdoo.shift.journal @@ -179,13 +180,13 @@ sequence="1" /> - + Counter Journal beesdoo.shift.journal tree,form - +