Browse Source

[ADD] Mechanism to change counter according to presence to shift or not + Option to not launch status mechanism

pull/105/head
Thibault Francois 7 years ago
committed by Elouan
parent
commit
cc4dd3d79e
  1. 7
      beesdoo_shift/data/stage.xml
  2. 12
      beesdoo_shift/data/system_parameter.xml
  3. 19
      beesdoo_shift/models/cooperative_status.py
  4. 59
      beesdoo_shift/models/task.py
  5. 9
      beesdoo_shift/views/cooperative_status.xml
  6. 3
      beesdoo_shift/views/task.xml
  7. 6
      beesdoo_shift/wizard/subscribe.py

7
beesdoo_shift/data/stage.xml

@ -3,35 +3,42 @@
<field name="name">Unconfirmed</field>
<field name="sequence">1</field>
<field name="color">0</field>
<field name="code">draft</field>
</record>
<record model="beesdoo.shift.stage" id="open">
<field name="name">Confirmed</field>
<field name="sequence">2</field>
<field name="color">5</field>
<field name="code">open</field>
</record>
<record model="beesdoo.shift.stage" id="done">
<field name="name">Attended</field>
<field name="sequence">3</field>
<field name="color">1</field>
<field name="code">done</field>
</record>
<record model="beesdoo.shift.stage" id="absent">
<field name="name">Absent</field>
<field name="sequence">5</field>
<field name="color">2</field>
<field name="code">absent</field>
</record>
<record model="beesdoo.shift.stage" id="excused">
<field name="name">Excused</field>
<field name="sequence">6</field>
<field name="color">4</field>
<field name="code">excused</field>
</record>
<record model="beesdoo.shift.stage" id="excused_necessity">
<field name="name">Excused - Absolute Necessity</field>
<field name="sequence">6</field>
<field name="color">4</field>
<field name="code">excused_necessity</field>
</record>
<record model="beesdoo.shift.stage" id="cancel">
<field name="name">Cancelled</field>
<field name="sequence">7</field>
<field name="color">8</field>
<field name="code">cancel</field>
</record>
</odoo>

12
beesdoo_shift/data/system_parameter.xml

@ -1,10 +1,18 @@
<odoo noupdate="1">
<record id="seq_solucom_matricule_cabinet" model="ir.config_parameter">
<record id="alert_delay_param" model="ir.config_parameter">
<field name="key">alert_delay</field>
<field name="value">28</field>
</record>
<record id="seq_solucom_matricule_cabinet" model="ir.config_parameter">
<record id="default_grace_delay" model="ir.config_parameter">
<field name="key">default_grace_delay</field>
<field name="value">10</field>
</record>
<record id="default_extension_delay" model="ir.config_parameter">
<field name="key">default_extension_delay</field>
<field name="value">28</field>
</record>
<record id="always_update" model="ir.config_parameter">
<field name="key">always_update</field>
<field name="value">0</field>
</record>
</odoo>

19
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

59
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 ?
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)

9
beesdoo_shift/views/cooperative_status.xml

@ -9,6 +9,14 @@
<button name="coop_subscribe" string="Subscribe to shift" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}"/>
<button name="auto_extension" string="Auto Extension" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': ['|',
('cooperator_type', '!=', 'share_a'),
'|',
('state', '!=', 'suspended'),
('extension_start_time', '!=', False)]}"/>
<field name="state" widget="statusbar" attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}" />
</header>
</xpath>
<page name="work" position="inside">
@ -17,6 +25,7 @@
<field name="info_session" />
<field name="info_session_date"
attrs="{'invisible': ['|', ('info_session', '=', False)]}" />
<field name="extension_start_time" attrs="{'invisible': [('extension_start_time', '=', False)]}" />
</group>
<group>
<field name="working_mode" />

3
beesdoo_shift/views/task.xml

@ -10,6 +10,7 @@
<field name="name" />
<field name="super_coop_id" />
<field name="worker_id" />
<field name="replaced_id" />
<field name="end_time" />
<field name="stage_id" />
</tree>
@ -91,7 +92,7 @@
<field name="task_type_id" />
<field name="super_coop_id" />
<field name="worker_id" />
<field name="replaced_id" />
<field name="replaced_id" attrs="{'invisible': [('is_regular', '!=', True)]}"/>
<field name="is_regular" />
</group>
<group>

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

Loading…
Cancel
Save