Browse Source

FIX stage status sequence

FIX default value for today on status
FIX default value for stage_id that allow to manually create shift
ADD un subscribed from shift during holidays
ADD Cannot subscribe to new holidays when you've already planned some holidays and they are not over yet
pull/105/head
Thibault Francois 7 years ago
committed by Elouan
parent
commit
48da2be7fb
  1. 4
      beesdoo_shift/data/stage.xml
  2. 2
      beesdoo_shift/models/cooperative_status.py
  3. 16
      beesdoo_shift/models/task.py
  4. 4
      beesdoo_shift/wizard/holiday.py

4
beesdoo_shift/data/stage.xml

@ -31,13 +31,13 @@
</record>
<record model="beesdoo.shift.stage" id="excused_necessity">
<field name="name">Excused - Absolute Necessity</field>
<field name="sequence">6</field>
<field name="sequence">7</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="sequence">8</field>
<field name="color">8</field>
<field name="code">cancel</field>
</record>

2
beesdoo_shift/models/cooperative_status.py

@ -32,7 +32,7 @@ class CooperativeStatus(models.Model):
_order = 'cooperator_id'
today = fields.Date(help="Field that allow to compute field and store them even if they are based on the current date")
today = fields.Date(help="Field that allow to compute field and store them even if they are based on the current date", default=fields.Date.today)
cooperator_id = fields.Many2one('res.partner')
info_session = fields.Boolean('Information Session ?')
info_session_date = fields.Datetime('Information Session Date')

16
beesdoo_shift/models/task.py

@ -31,7 +31,7 @@ class Task(models.Model):
worker_id = fields.Many2one('res.partner', track_visibility='onchange', domain=[('eater', '=', 'worker_eater')])
start_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')
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')
color = fields.Integer(related="stage_id.color", readonly=True)
is_regular = fields.Boolean(default=False)
@ -59,14 +59,20 @@ class Task(models.Model):
#TODO button to replaced someone
@api.model
def unsubscribe_from_today(self, worker_ids, today=None):
def unsubscribe_from_today(self, worker_ids, today=None, end_date=None):
today = today or fields.Date.today()
today = today + ' 00:00:00'
to_unsubscribe = self.search([('worker_id', 'in', worker_ids), ('start_time', '>=', today)])
today += ' 00:00:00'
if end_date:
end_date += ' 23:59:59'
date_domain = [('worker_id', 'in', worker_ids), ('start_time', '>=', today)]
if end_date:
date_domain.append(('end_time', '<=', end_date))
to_unsubscribe = self.search([('worker_id', 'in', worker_ids)] + date_domain)
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 = self.search([('replaced_id', 'in', worker_ids)] + date_domain)
to_unsubscribe_replace.write({'worker_id': False, 'is_regular': False, 'replaced_id': False})
@api.multi

4
beesdoo_shift/wizard/holiday.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
class Subscribe(models.TransientModel):
_name = 'beesdoo.shift.holiday'
@ -12,4 +13,7 @@ class Subscribe(models.TransientModel):
def holidays(self):
self = self._check() #maybe a different group
status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
if status_id.holiday_end_time >= status_id.today:
raise ValidationError(_("You cannot encode new holidays since the previous holidays encoded are not over yet"))
status_id.sudo().write({'holiday_start_time': self.holiday_start_day, 'holiday_end_time': self.holiday_end_day})
self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today([self.cooperator_id.id], today=self.holiday_start_day, end_date=self.holiday_end_day)
Loading…
Cancel
Save