Browse Source

[ADD] beesdoo_shift: S0048 temporary exemption

9.0-shift6-welcome_screen-tfr
Thibault Francois 7 years ago
parent
commit
9f269c4849
  1. 1
      beesdoo_shift/__openerp__.py
  2. 28
      beesdoo_shift/models/cooperative_status.py
  3. 5
      beesdoo_shift/models/planning.py
  4. 2
      beesdoo_shift/models/task.py
  5. 14
      beesdoo_shift/views/cooperative_status.xml
  6. 1
      beesdoo_shift/wizard/__init__.py
  7. 24
      beesdoo_shift/wizard/temporary_exemption.py
  8. 21
      beesdoo_shift/wizard/temporary_exemption.xml

1
beesdoo_shift/__openerp__.py

@ -34,5 +34,6 @@
"wizard/subscribe.xml", "wizard/subscribe.xml",
"wizard/extension.xml", "wizard/extension.xml",
"wizard/holiday.xml", "wizard/holiday.xml",
"wizard/temporary_exemption.xml",
], ],
} }

28
beesdoo_shift/models/cooperative_status.py

@ -63,6 +63,7 @@ class CooperativeStatus(models.Model):
('alert', 'Alerte'), ('alert', 'Alerte'),
('extension', 'Extension'), ('extension', 'Extension'),
('suspended', 'Suspended'), ('suspended', 'Suspended'),
('exempted', 'Exempted'),
('unsubscribed', 'Unsubscribed')], ('unsubscribed', 'Unsubscribed')],
compute="_compute_status", string="Cooperative Status", store=True) compute="_compute_status", string="Cooperative Status", store=True)
can_shop = fields.Boolean(compute='_compute_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_date = fields.Date()
irregular_absence_counter = fields.Integer() #TODO unsubscribe when reach -2 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', @api.depends('today', 'sr', 'sc', 'holiday_end_time',
'holiday_start_time', 'time_extension', 'holiday_start_time', 'time_extension',
'alert_start_time', 'extension_start_time', 'alert_start_time', 'extension_start_time',
'unsubscribed', 'irregular_absence_date', 'unsubscribed', 'irregular_absence_date',
'irregular_absence_counter')
'irregular_absence_counter', 'temporary_exempt_start_date',
'temporary_exempt_end_date')
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))
@ -106,6 +112,9 @@ class CooperativeStatus(models.Model):
if self.sr < -1 or self.unsubscribed: if self.sr < -1 or self.unsubscribed:
self.status = 'unsubscribed' self.status = 'unsubscribed'
self.can_shop = False 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 #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): 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() self.ensure_one()
ok = self.sr >= 0 ok = self.sr >= 0
grace_delay = grace_delay + self.time_extension 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)) \ 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: or self.unsubscribed or self.irregular_absence_counter <= -2:
self.status = 'unsubscribed' self.status = 'unsubscribed'
self.can_shop = False 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 #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): 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' self.status = 'extension'
@ -246,6 +257,8 @@ class CooperativeStatus(models.Model):
irregular = self.search([('status', '!=', 'unsubscribed'), ('working_mode', '=', 'irregular'), ('irregular_start_date', '!=', False)]) irregular = self.search([('status', '!=', 'unsubscribed'), ('working_mode', '=', 'irregular'), ('irregular_start_date', '!=', False)])
today_date = fields.Date.from_string(today) today_date = fields.Date.from_string(today)
for status in irregular: for status in irregular:
if status.status == 'exempted':
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 % 28 == 0 and status not in journal.line_ids: #TODO use system parameter for 28
if status.sr > 0: if status.sr > 0:
@ -333,5 +346,16 @@ class ResPartner(models.Model):
'target': 'new', '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 access right + vue on res.partner
#TODO can_shop : Status can_shop ou extempted ou part C #TODO can_shop : Status can_shop ou extempted ou part C

5
beesdoo_shift/models/planning.py

@ -141,12 +141,15 @@ class TaskTemplate(models.Model):
for rec in self: for rec in self:
for i in xrange(0, rec.worker_nb): for i in xrange(0, rec.worker_nb):
worker_id = rec.worker_ids[i] if len(rec.worker_ids) > i else False 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: if worker_id and worker_id.cooperative_status_ids:
status = worker_id.cooperative_status_ids[0] status = worker_id.cooperative_status_ids[0]
if status.holiday_start_time and status.holiday_end_time and \ 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]: status.holiday_start_time <= rec.start_date[:10] and status.holiday_end_time >= rec.end_date[:10]:
worker_id = False 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({ 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), '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, 'task_template_id' : rec.id,

2
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) planning_id = fields.Many2one(related='task_template_id.planning_id', store=True)
task_type_id = fields.Many2one('beesdoo.shift.type', string="Task Type") task_type_id = fields.Many2one('beesdoo.shift.type', string="Task Type")
worker_id = fields.Many2one('res.partner', track_visibility='onchange', domain=[('eater', '=', 'worker_eater')]) 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') 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')) 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') super_coop_id = fields.Many2one('res.users', string="Super Cooperative", domain=[('partner_id.super', '=', True)], track_visibility='onchange')

14
beesdoo_shift/views/cooperative_status.xml

@ -29,6 +29,9 @@
<button name="register_holiday" string="Register Holidays" class="oe_highlight" <button name="register_holiday" string="Register Holidays" 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'), ('state', '!=', 'ok')]}"/> attrs="{'invisible': ['|', ('cooperator_type', '!=', 'share_a'), ('state', '!=', 'ok')]}"/>
<button name="temporary_exempt" string="Temporary Exemption"
type="object" groups="beesdoo_shift.group_shift_management"
attrs="{'invisible': ['|', ('cooperator_type', '!=', 'share_a'), ('state', '=', 'unsubscribed')]}"/>
<field name="state" widget="statusbar" attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}" /> <field name="state" widget="statusbar" attrs="{'invisible': [('cooperator_type', '!=', 'share_a')]}" />
</header> </header>
</xpath> </xpath>
@ -61,7 +64,7 @@
<field name="status" widget="statusbar" /> <field name="status" widget="statusbar" />
</header> </header>
<group> <group>
<group>
<group string="General information">
<field name="cooperator_id" /> <field name="cooperator_id" />
<field name="super" /> <field name="super" />
<field name="working_mode" /> <field name="working_mode" />
@ -70,7 +73,7 @@
<field name="exempt_reason_id" attrs="{'invisible':[('working_mode', '!=', 'exempt')]}"/> <field name="exempt_reason_id" attrs="{'invisible':[('working_mode', '!=', 'exempt')]}"/>
</group> </group>
<group>
<group string="Counter and Status">
<field name="info_session" /> <field name="info_session" />
<field name="info_session_date" /> <field name="info_session_date" />
<field name="sr" /> <field name="sr" />
@ -79,13 +82,18 @@
<field name="unsubscribed" /> <field name="unsubscribed" />
<field name="can_shop" /> <field name="can_shop" />
</group> </group>
<group>
<group string="Timing information">
<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" />
<field name="alert_start_time" /> <field name="alert_start_time" />
<field name="extension_start_time" /> <field name="extension_start_time" />
</group> </group>
<group string="Temporary Exemption">
<field name="temporary_exempt_reason_id" />
<field name="temporary_exempt_start_date" />
<field name="temporary_exempt_end_date" />
</group>
</group> </group>
<group groups="base.group_no_one" col="3"> <group groups="base.group_no_one" col="3">
<separator string="For testing purpose only" colspan="3"/> <separator string="For testing purpose only" colspan="3"/>

1
beesdoo_shift/wizard/__init__.py

@ -4,3 +4,4 @@ import assign_super_coop
import subscribe import subscribe
import extension import extension
import holiday import holiday
import temporary_exemption

24
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)

21
beesdoo_shift/wizard/temporary_exemption.xml

@ -0,0 +1,21 @@
<odoo>
<record model="ir.ui.view" id="holiday_coop_wizard_view_form">
<field name="name">Temporary Exemption</field>
<field name="model">beesdoo.shift.temporary_exemption</field>
<field name="arch" type="xml">
<form>
<field name="cooperator_id" invisible="1"/>
<group>
<field name="temporary_exempt_reason_id" />
<field name="temporary_exempt_start_date" />
<field name="temporary_exempt_end_date" />
</group>
<footer>
<button type="object" name="exempt"
string="Confirm" class="oe_highlight" />
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>
</record>
</odoo>
Loading…
Cancel
Save