diff --git a/beesdoo_shift/__openerp__.py b/beesdoo_shift/__openerp__.py
index e6f8a71..7ff8d95 100644
--- a/beesdoo_shift/__openerp__.py
+++ b/beesdoo_shift/__openerp__.py
@@ -34,5 +34,6 @@
"wizard/subscribe.xml",
"wizard/extension.xml",
"wizard/holiday.xml",
+ "wizard/temporary_exemption.xml",
],
}
diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py
index 6fbb170..218361d 100644
--- a/beesdoo_shift/models/cooperative_status.py
+++ b/beesdoo_shift/models/cooperative_status.py
@@ -63,6 +63,7 @@ class CooperativeStatus(models.Model):
('alert', 'Alerte'),
('extension', 'Extension'),
('suspended', 'Suspended'),
+ ('exempted', 'Exempted'),
('unsubscribed', 'Unsubscribed')],
compute="_compute_status", string="Cooperative Status", store=True)
can_shop = fields.Boolean(compute='_compute_status', store=True)
@@ -74,12 +75,17 @@ class CooperativeStatus(models.Model):
irregular_absence_date = fields.Date()
irregular_absence_counter = fields.Integer() #TODO unsubscribe when reach -2
+ temporary_exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason')
+ temporary_exempt_start_date = fields.Date()
+ temporary_exempt_end_date = fields.Date()
+
@api.depends('today', 'sr', 'sc', 'holiday_end_time',
'holiday_start_time', 'time_extension',
'alert_start_time', 'extension_start_time',
'unsubscribed', 'irregular_absence_date',
- 'irregular_absence_counter')
+ 'irregular_absence_counter', 'temporary_exempt_start_date',
+ 'temporary_exempt_end_date')
def _compute_status(self):
alert_delay = int(self.env['ir.config_parameter'].get_param('alert_delay', 28))
grace_delay = int(self.env['ir.config_parameter'].get_param('default_grace_delay', 10))
@@ -106,6 +112,9 @@ class CooperativeStatus(models.Model):
if self.sr < -1 or self.unsubscribed:
self.status = 'unsubscribed'
self.can_shop = False
+ elif self.today >= self.temporary_exempt_start_date and self.today <= self.temporary_exempt_end_date:
+ self.status = 'exempted'
+ self.can_shop = True
#Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined
elif not ok and self.alert_start_time and self.extension_start_time and self.today <= add_days_delta(self.extension_start_time, grace_delay):
@@ -133,11 +142,13 @@ class CooperativeStatus(models.Model):
self.ensure_one()
ok = self.sr >= 0
grace_delay = grace_delay + self.time_extension
- print add_days_delta(self.extension_start_time, grace_delay)
if (not ok and self.irregular_absence_date and self.today > add_days_delta(self.irregular_absence_date, alert_delay * 2)) \
or self.unsubscribed or self.irregular_absence_counter <= -2:
self.status = 'unsubscribed'
self.can_shop = False
+ elif self.today >= self.temporary_exempt_start_date and self.today <= self.temporary_exempt_end_date:
+ self.status = 'exempted'
+ self.can_shop = True
#Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined
elif not ok and self.alert_start_time and self.extension_start_time and self.today <= add_days_delta(self.extension_start_time, grace_delay):
self.status = 'extension'
@@ -246,6 +257,8 @@ class CooperativeStatus(models.Model):
irregular = self.search([('status', '!=', 'unsubscribed'), ('working_mode', '=', 'irregular'), ('irregular_start_date', '!=', False)])
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
if delta and delta % 28 == 0 and status not in journal.line_ids: #TODO use system parameter for 28
if status.sr > 0:
@@ -333,5 +346,16 @@ class ResPartner(models.Model):
'target': 'new',
}
+ @api.multi
+ def temporary_exempt(self):
+ return {
+ 'name': _('Temporary Exemption'),
+ 'type': 'ir.actions.act_window',
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'beesdoo.shift.temporary_exemption',
+ 'target': 'new',
+ }
+
#TODO access right + vue on res.partner
#TODO can_shop : Status can_shop ou extempted ou part C
diff --git a/beesdoo_shift/models/planning.py b/beesdoo_shift/models/planning.py
index dc8b8b7..fd87ab7 100644
--- a/beesdoo_shift/models/planning.py
+++ b/beesdoo_shift/models/planning.py
@@ -141,12 +141,15 @@ class TaskTemplate(models.Model):
for rec in self:
for i in xrange(0, rec.worker_nb):
worker_id = rec.worker_ids[i] if len(rec.worker_ids) > i else False
- #remove worker in holiday
+ #remove worker in holiday and temporary exempted
if worker_id and worker_id.cooperative_status_ids:
status = worker_id.cooperative_status_ids[0]
if status.holiday_start_time and status.holiday_end_time and \
status.holiday_start_time <= rec.start_date[:10] and status.holiday_end_time >= rec.end_date[:10]:
worker_id = False
+ if status.temporary_exempt_start_date and status.temporary_exempt_end_date and \
+ status.temporary_exempt_start_date <= rec.start_date[:10] and status.temporary_exempt_end_date >= rec.end_date[:10]:
+ 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),
'task_template_id' : rec.id,
diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py
index 6058c2b..39121fc 100644
--- a/beesdoo_shift/models/task.py
+++ b/beesdoo_shift/models/task.py
@@ -29,7 +29,7 @@ class Task(models.Model):
planning_id = fields.Many2one(related='task_template_id.planning_id', store=True)
task_type_id = fields.Many2one('beesdoo.shift.type', string="Task Type")
worker_id = fields.Many2one('res.partner', track_visibility='onchange', domain=[('eater', '=', 'worker_eater')])
- start_time = fields.Datetime(track_visibility='always')
+ start_time = fields.Datetime(track_visibility='always', index=True)
end_time = fields.Datetime(track_visibility='always')
stage_id = fields.Many2one('beesdoo.shift.stage', required=True, track_visibility='onchange', default=lambda self: self.env.ref('beesdoo_shift.open'))
super_coop_id = fields.Many2one('res.users', string="Super Cooperative", domain=[('partner_id.super', '=', True)], track_visibility='onchange')
diff --git a/beesdoo_shift/views/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml
index 39322a6..6273a25 100644
--- a/beesdoo_shift/views/cooperative_status.xml
+++ b/beesdoo_shift/views/cooperative_status.xml
@@ -29,6 +29,9 @@
+
@@ -61,7 +64,7 @@
-
+
@@ -70,7 +73,7 @@
-
+
@@ -79,13 +82,18 @@
-
+
+
+
+
+
+
diff --git a/beesdoo_shift/wizard/__init__.py b/beesdoo_shift/wizard/__init__.py
index 2aa4b25..59863f5 100644
--- a/beesdoo_shift/wizard/__init__.py
+++ b/beesdoo_shift/wizard/__init__.py
@@ -3,4 +3,5 @@ import batch_template
import assign_super_coop
import subscribe
import extension
-import holiday
\ No newline at end of file
+import holiday
+import temporary_exemption
\ No newline at end of file
diff --git a/beesdoo_shift/wizard/temporary_exemption.py b/beesdoo_shift/wizard/temporary_exemption.py
new file mode 100644
index 0000000..f19e430
--- /dev/null
+++ b/beesdoo_shift/wizard/temporary_exemption.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from openerp import models, fields, api, _
+from openerp.exceptions import ValidationError
+
+class TemporaryExemption(models.TransientModel):
+ _name = 'beesdoo.shift.temporary_exemption'
+ _inherit = 'beesdoo.shift.action_mixin'
+
+ temporary_exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason', required=True)
+ temporary_exempt_start_date = fields.Date(default=fields.Date.today, required=True)
+ temporary_exempt_end_date = fields.Date(required=True)
+
+ @api.multi
+ def exempt(self):
+ self = self._check() #maybe a different group
+ status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
+ if status_id.temporary_exempt_end_date >= status_id.today:
+ raise ValidationError(_("You cannot encode new temporary exemptuon since the previous one are not over yet"))
+ status_id.sudo().write({
+ 'temporary_exempt_start_date': self.temporary_exempt_start_date,
+ 'temporary_exempt_end_date': self.temporary_exempt_end_date,
+ 'temporary_exempt_reason_id': self.temporary_exempt_reason_id.id,
+ })
+ self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today([self.cooperator_id.id], today=self.temporary_exempt_start_date, end_date=self.temporary_exempt_end_date)
diff --git a/beesdoo_shift/wizard/temporary_exemption.xml b/beesdoo_shift/wizard/temporary_exemption.xml
new file mode 100644
index 0000000..73df0bc
--- /dev/null
+++ b/beesdoo_shift/wizard/temporary_exemption.xml
@@ -0,0 +1,21 @@
+
+
+ Temporary Exemption
+ beesdoo.shift.temporary_exemption
+
+
+
+
+