Browse Source

[ADD] beesdoo_shift: Future alert date

pull/105/head
Rémy Taymans 7 years ago
committed by Elouan
parent
commit
604b74a2dc
  1. 16
      beesdoo_shift/models/cooperative_status.py
  2. 1
      beesdoo_shift/views/cooperative_status.xml

16
beesdoo_shift/models/cooperative_status.py

@ -7,6 +7,7 @@ import logging
from openerp.osv.fields import related from openerp.osv.fields import related
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
PERIOD = 28 # TODO: use system parameter
def add_days_delta(date_from, days_delta): def add_days_delta(date_from, days_delta):
if not date_from: if not date_from:
@ -76,6 +77,7 @@ class CooperativeStatus(models.Model):
irregular_start_date = fields.Date() #TODO migration script irregular_start_date = fields.Date() #TODO migration script
irregular_absence_date = fields.Date() irregular_absence_date = fields.Date()
irregular_absence_counter = fields.Integer() #TODO unsubscribe when reach -2 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_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason')
temporary_exempt_start_date = fields.Date() temporary_exempt_start_date = fields.Date()
@ -110,6 +112,18 @@ class CooperativeStatus(models.Model):
rec.status = 'ok' rec.status = 'ok'
rec.can_shop = True 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): def _set_regular_status(self, grace_delay, alert_delay):
self.ensure_one() self.ensure_one()
ok = self.sr >= 0 and self.sc >= 0 ok = self.sr >= 0 and self.sc >= 0
@ -266,7 +280,7 @@ class CooperativeStatus(models.Model):
if status.status == 'exempted': if status.status == 'exempted':
continue continue
delta = (today_date - fields.Date.from_string(status.irregular_start_date)).days 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: if status.sr > 0:
status.sr -= 1 status.sr -= 1
else: else:

1
beesdoo_shift/views/cooperative_status.xml

@ -84,6 +84,7 @@
<field name="can_shop" /> <field name="can_shop" />
</group> </group>
<group string="Timing information"> <group string="Timing information">
<field name="future_alert_date" readonly="1" />
<field name="time_extension" /> <field name="time_extension" />
<field name="holiday_start_time" /> <field name="holiday_start_time" />
<field name="holiday_end_time" /> <field name="holiday_end_time" />

Loading…
Cancel
Save