Browse Source

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

pull/19/head
Thibault Francois 8 years ago
parent
commit
c4d2026cbc
  1. 7
      beesdoo_shift/data/stage.xml
  2. 12
      beesdoo_shift/data/system_parameter.xml
  3. 19
      beesdoo_shift/models/cooperative_status.py
  4. 57
      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="name">Unconfirmed</field>
<field name="sequence">1</field> <field name="sequence">1</field>
<field name="color">0</field> <field name="color">0</field>
<field name="code">draft</field>
</record> </record>
<record model="beesdoo.shift.stage" id="open"> <record model="beesdoo.shift.stage" id="open">
<field name="name">Confirmed</field> <field name="name">Confirmed</field>
<field name="sequence">2</field> <field name="sequence">2</field>
<field name="color">5</field> <field name="color">5</field>
<field name="code">open</field>
</record> </record>
<record model="beesdoo.shift.stage" id="done"> <record model="beesdoo.shift.stage" id="done">
<field name="name">Attended</field> <field name="name">Attended</field>
<field name="sequence">3</field> <field name="sequence">3</field>
<field name="color">1</field> <field name="color">1</field>
<field name="code">done</field>
</record> </record>
<record model="beesdoo.shift.stage" id="absent"> <record model="beesdoo.shift.stage" id="absent">
<field name="name">Absent</field> <field name="name">Absent</field>
<field name="sequence">5</field> <field name="sequence">5</field>
<field name="color">2</field> <field name="color">2</field>
<field name="code">absent</field>
</record> </record>
<record model="beesdoo.shift.stage" id="excused"> <record model="beesdoo.shift.stage" id="excused">
<field name="name">Excused</field> <field name="name">Excused</field>
<field name="sequence">6</field> <field name="sequence">6</field>
<field name="color">4</field> <field name="color">4</field>
<field name="code">excused</field>
</record> </record>
<record model="beesdoo.shift.stage" id="excused_necessity"> <record model="beesdoo.shift.stage" id="excused_necessity">
<field name="name">Excused - Absolute Necessity</field> <field name="name">Excused - Absolute Necessity</field>
<field name="sequence">6</field> <field name="sequence">6</field>
<field name="color">4</field> <field name="color">4</field>
<field name="code">excused_necessity</field>
</record> </record>
<record model="beesdoo.shift.stage" id="cancel"> <record model="beesdoo.shift.stage" id="cancel">
<field name="name">Cancelled</field> <field name="name">Cancelled</field>
<field name="sequence">7</field> <field name="sequence">7</field>
<field name="color">8</field> <field name="color">8</field>
<field name="code">cancel</field>
</record> </record>
</odoo> </odoo>

12
beesdoo_shift/data/system_parameter.xml

@ -1,10 +1,18 @@
<odoo noupdate="1"> <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="key">alert_delay</field>
<field name="value">28</field> <field name="value">28</field>
</record> </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="key">default_grace_delay</field>
<field name="value">10</field> <field name="value">10</field>
</record> </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> </odoo>

19
beesdoo_shift/models/cooperative_status.py

@ -56,8 +56,7 @@ class CooperativeStatus(models.Model):
status = fields.Selection([('ok', 'Up to Date'), status = fields.Selection([('ok', 'Up to Date'),
('holiday', 'Holidays'), ('holiday', 'Holidays'),
('alert', 'Alerte'), ('alert', 'Alerte'),
('extension', 'Suspended (auto ext)'),
('extension_current', 'In extension'),
('extension', 'Extension'),
('suspended', 'Suspended'), ('suspended', 'Suspended'),
('unsubscribed', 'Unsubscribed')], ('unsubscribed', 'Unsubscribed')],
compute="_compute_status", string="Cooperative Status", store=True) compute="_compute_status", string="Cooperative Status", store=True)
@ -70,7 +69,14 @@ class CooperativeStatus(models.Model):
def _compute_status(self): def _compute_status(self):
alert_delay = int(self.env['ir.config_parameter'].get_param('alert_delay', 28)) 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)) 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: for rec in self:
if update:
rec.status = 'ok'
rec.can_shop = True
continue
ok = rec.sr >= 0 and rec.sc >= 0 ok = rec.sr >= 0 and rec.sc >= 0
grace_delay = grace_delay + rec.time_extension 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 #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): 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 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): 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.status = 'suspended'
rec.can_shop = False rec.can_shop = False
elif not ok and rec.alert_start_time and rec.today > add_days_delta(rec.alert_start_time, alert_delay): 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 rec.can_shop = False
elif (rec.sr < 0) or (not ok and rec.alert_start_time): elif (rec.sr < 0) or (not ok and rec.alert_start_time):
rec.status = 'alert' rec.status = 'alert'
@ -122,6 +128,7 @@ class CooperativeStatus(models.Model):
return super(CooperativeStatus, self).write(vals) return super(CooperativeStatus, self).write(vals)
def _state_change(self, new_state, old_stage): def _state_change(self, new_state, old_stage):
self.ensure_one()
if new_state == 'alert': if new_state == 'alert':
self.write({'alert_start_time': self.today, 'extension_start_time': False, 'time_extension': 0}) 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 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) 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) 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) 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') subscribed_shift_ids = fields.Many2many('beesdoo.shift.template')
@api.multi @api.multi
def coop_subscribe(self): def coop_subscribe(self):
return { return {
@ -191,3 +201,4 @@ class ResPartner(models.Model):
} }
#TODO access right + vue on res.partner #TODO access right + vue on res.partner
#TODO can_shop : Status can_shop ou extempted ou part C

57
beesdoo_shift/models/task.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import models, fields, api from openerp import models, fields, api
from openerp.exceptions import UserError
class TaskStage(models.Model): class TaskStage(models.Model):
_name = 'beesdoo.shift.stage' _name = 'beesdoo.shift.stage'
@ -8,6 +9,11 @@ class TaskStage(models.Model):
name = fields.Char() name = fields.Char()
sequence = fields.Integer() sequence = fields.Integer()
color = 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): class Task(models.Model):
@ -55,5 +61,54 @@ class Task(models.Model):
today = today or fields.Date.today() today = today or fields.Date.today()
today = today + ' 00:00:00' today = today + ' 00:00:00'
to_unsubscribe = self.search([('worker_id', 'in', worker_ids), ('start_time', '>=', today)]) to_unsubscribe = self.search([('worker_id', 'in', worker_ids), ('start_time', '>=', today)])
to_unsubscribe.write({'worker_id': False})
to_unsubscribe.write({'worker_id': False, 'is_regular': False})
#What about replacement ? #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" <button name="coop_subscribe" string="Subscribe to shift" class="oe_highlight"
type="object" groups="beesdoo_shift.group_shift_management" type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}"/> 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> </header>
</xpath> </xpath>
<page name="work" position="inside"> <page name="work" position="inside">
@ -17,6 +25,7 @@
<field name="info_session" /> <field name="info_session" />
<field name="info_session_date" <field name="info_session_date"
attrs="{'invisible': ['|', ('info_session', '=', False)]}" /> attrs="{'invisible': ['|', ('info_session', '=', False)]}" />
<field name="extension_start_time" attrs="{'invisible': [('extension_start_time', '=', False)]}" />
</group> </group>
<group> <group>
<field name="working_mode" /> <field name="working_mode" />

3
beesdoo_shift/views/task.xml

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

6
beesdoo_shift/wizard/subscribe.py

@ -57,12 +57,12 @@ class Subscribe(models.TransientModel):
'exempt_reason_id' : self.exempt_reason_id.id, 'exempt_reason_id' : self.exempt_reason_id.id,
'super' : self.super, 'super' : self.super,
'cooperator_id': self.cooperator_id.id, 'cooperator_id': self.cooperator_id.id,
'extension_start_time': False,
'alert_start_time': False,
'time_extension': 0,
} }
if self.reset_counter: if self.reset_counter:
data['sr'] = 0 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)]) status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
if status_id: if status_id:

Loading…
Cancel
Save