diff --git a/beesdoo_shift/data/stage.xml b/beesdoo_shift/data/stage.xml
index 6d7f19e..73fcc0c 100644
--- a/beesdoo_shift/data/stage.xml
+++ b/beesdoo_shift/data/stage.xml
@@ -3,35 +3,42 @@
Unconfirmed
1
0
+ draft
Confirmed
2
5
+ open
Attended
3
1
+ done
Absent
5
2
+ absent
Excused
6
4
+ excused
Excused - Absolute Necessity
6
4
+ excused_necessity
Cancelled
7
8
+ cancel
diff --git a/beesdoo_shift/data/system_parameter.xml b/beesdoo_shift/data/system_parameter.xml
index c106f6d..1aef808 100644
--- a/beesdoo_shift/data/system_parameter.xml
+++ b/beesdoo_shift/data/system_parameter.xml
@@ -1,10 +1,18 @@
-
+
alert_delay
28
-
+
default_grace_delay
10
+
+ default_extension_delay
+ 28
+
+
+ always_update
+ 0
+
\ No newline at end of file
diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py
index 4af346a..8ad8ce4 100644
--- a/beesdoo_shift/models/cooperative_status.py
+++ b/beesdoo_shift/models/cooperative_status.py
@@ -56,8 +56,7 @@ class CooperativeStatus(models.Model):
status = fields.Selection([('ok', 'Up to Date'),
('holiday', 'Holidays'),
('alert', 'Alerte'),
- ('extension', 'Suspended (auto ext)'),
- ('extension_current', 'In extension'),
+ ('extension', 'Extension'),
('suspended', 'Suspended'),
('unsubscribed', 'Unsubscribed')],
compute="_compute_status", string="Cooperative Status", store=True)
@@ -70,7 +69,14 @@ class CooperativeStatus(models.Model):
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))
+ update = int(self.env['ir.config_parameter'].get_param('always_update', False))
+ print update
for rec in self:
+ if update:
+ rec.status = 'ok'
+ rec.can_shop = True
+ continue
+
ok = rec.sr >= 0 and rec.sc >= 0
grace_delay = grace_delay + rec.time_extension
@@ -80,13 +86,13 @@ class CooperativeStatus(models.Model):
#Transition to alert sr < 0 or stay in alert sr < 0 or sc < 0 and thus alert time is defined
elif not ok and rec.alert_start_time and rec.extension_start_time and rec.today <= add_days_delta(rec.extension_start_time, grace_delay):
- rec.status = 'extension_current'
+ rec.status = 'extension'
rec.can_shop = True
elif not ok and rec.alert_start_time and rec.extension_start_time and rec.today > add_days_delta(rec.extension_start_time, grace_delay):
rec.status = 'suspended'
rec.can_shop = False
elif not ok and rec.alert_start_time and rec.today > add_days_delta(rec.alert_start_time, alert_delay):
- rec.status = 'extension'
+ rec.status = 'suspended'
rec.can_shop = False
elif (rec.sr < 0) or (not ok and rec.alert_start_time):
rec.status = 'alert'
@@ -122,6 +128,7 @@ class CooperativeStatus(models.Model):
return super(CooperativeStatus, self).write(vals)
def _state_change(self, new_state, old_stage):
+ self.ensure_one()
if new_state == 'alert':
self.write({'alert_start_time': self.today, 'extension_start_time': False, 'time_extension': 0})
if new_state == 'ok': #reset alert start time if back to ok
@@ -178,7 +185,10 @@ class ResPartner(models.Model):
info_session_date = fields.Datetime(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True)
working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True)
exempt_reason_id = fields.Many2one(related='cooperative_status_ids.exempt_reason_id', readonly=True, store=True)
+ state = fields.Selection(related='cooperative_status_ids.status', readonly=True, store=True)
+ extension_start_time = fields.Date(related='cooperative_status_ids.extension_start_time', string="Extension Start Day", readonly=True, store=True)
subscribed_shift_ids = fields.Many2many('beesdoo.shift.template')
+
@api.multi
def coop_subscribe(self):
return {
@@ -191,3 +201,4 @@ class ResPartner(models.Model):
}
#TODO access right + vue on res.partner
+ #TODO can_shop : Status can_shop ou extempted ou part C
diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py
index 4e3ebe4..4e0331d 100644
--- a/beesdoo_shift/models/task.py
+++ b/beesdoo_shift/models/task.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api
+from openerp.exceptions import UserError
class TaskStage(models.Model):
_name = 'beesdoo.shift.stage'
@@ -8,6 +9,11 @@ class TaskStage(models.Model):
name = fields.Char()
sequence = fields.Integer()
color = fields.Integer()
+ code = fields.Char(readonly=True)
+
+ @api.multi
+ def unlink(self):
+ raise UserError(_("You Cannot delete Task Stage"))
class Task(models.Model):
@@ -55,5 +61,54 @@ class Task(models.Model):
today = today or fields.Date.today()
today = today + ' 00:00:00'
to_unsubscribe = self.search([('worker_id', 'in', worker_ids), ('start_time', '>=', today)])
- to_unsubscribe.write({'worker_id': False})
- #What about replacement ?
\ No newline at end of file
+ to_unsubscribe.write({'worker_id': False, 'is_regular': False})
+ #What about replacement ?
+ #Remove worker, replaced_id and regular
+ to_unsubscribe_replace = self.search([('replaced_id', 'in', worker_ids), ('start_time', '>=', today)])
+ to_unsubscribe_replace.write({'worker_id': False, 'is_regular': False, 'replaced_id': False})
+
+ @api.multi
+ def write(self, vals):
+ """
+ Overwrite write to track stage change
+ """
+ if 'stage_id' in vals:
+ for rec in self:
+ if vals['stage_id'] != rec.stage_id.id:
+ rec._update_stage(rec.stage_id.id, vals['stage_id'])
+ return super(Task, self).write(vals)
+
+ def _update_stage(self, old_stage, new_stage):
+ self.ensure_one()
+ update = int(self.env['ir.config_parameter'].get_param('always_update', False))
+ if not (self.worker_id or self.replaced_id) or update:
+ return
+ new_stage = self.env['beesdoo.shift.stage'].browse(new_stage)
+
+ if not self.replaced_id: #No replacement case
+ status = self.worker_id.cooperative_status_ids[0]
+ else:
+ status = self.replaced_id.cooperative_status_ids[0]
+
+ data = {}
+ if new_stage == self.env.ref('beesdoo_shift.done') and self.is_regular:
+ pass
+ if new_stage == self.env.ref('beesdoo_shift.done') and not self.is_regular:
+ if status.sr < 0:
+ data['sr'] = status.sr + 1
+ elif status.sc < 0:
+ data['sc'] = status.sc + 1
+ else:
+ data['sr'] = status.sr + 1
+
+ if new_stage == self.env.ref('beesdoo_shift.absent') and not self.replaced_id:
+ data['sr'] = status.sr - 1
+ if status.sr <= 0:
+ data['sc'] = status.sc -1
+ if new_stage == self.env.ref('beesdoo_shift.absent') and self.replaced_id:
+ data['sr'] = status.sr -1
+
+ if new_stage == self.env.ref('beesdoo_shift.excused'):
+ data['sr'] = status.sr -1
+
+ status.sudo().write(data)
diff --git a/beesdoo_shift/views/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml
index 798ae83..904063b 100644
--- a/beesdoo_shift/views/cooperative_status.xml
+++ b/beesdoo_shift/views/cooperative_status.xml
@@ -9,6 +9,14 @@
+
+
@@ -17,6 +25,7 @@
+
diff --git a/beesdoo_shift/views/task.xml b/beesdoo_shift/views/task.xml
index f601639..2a5b45a 100644
--- a/beesdoo_shift/views/task.xml
+++ b/beesdoo_shift/views/task.xml
@@ -10,6 +10,7 @@
+
@@ -91,7 +92,7 @@
-
+
diff --git a/beesdoo_shift/wizard/subscribe.py b/beesdoo_shift/wizard/subscribe.py
index c7d91f7..9790b3f 100644
--- a/beesdoo_shift/wizard/subscribe.py
+++ b/beesdoo_shift/wizard/subscribe.py
@@ -57,12 +57,12 @@ class Subscribe(models.TransientModel):
'exempt_reason_id' : self.exempt_reason_id.id,
'super' : self.super,
'cooperator_id': self.cooperator_id.id,
- 'extension_start_time': False,
- 'alert_start_time': False,
- 'time_extension': 0,
}
if self.reset_counter:
data['sr'] = 0
+ data['extension_start_time'] = False
+ data['alert_start_time'] = False
+ data['time_extension'] = 0
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
if status_id: