From 48da2be7fb661e500fab121fb0ef232ebb4fde1b Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Wed, 1 Nov 2017 17:34:19 +0100 Subject: [PATCH] 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 --- beesdoo_shift/data/stage.xml | 4 ++-- beesdoo_shift/models/cooperative_status.py | 2 +- beesdoo_shift/models/task.py | 16 +++++++++++----- beesdoo_shift/wizard/holiday.py | 4 ++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/beesdoo_shift/data/stage.xml b/beesdoo_shift/data/stage.xml index 73fcc0c..b4d69ed 100644 --- a/beesdoo_shift/data/stage.xml +++ b/beesdoo_shift/data/stage.xml @@ -31,13 +31,13 @@ Excused - Absolute Necessity - 6 + 7 4 excused_necessity Cancelled - 7 + 8 8 cancel diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index 6c9fe58..886e306 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/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') diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 41a16d2..9deb853 100644 --- a/beesdoo_shift/models/task.py +++ b/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 diff --git a/beesdoo_shift/wizard/holiday.py b/beesdoo_shift/wizard/holiday.py index f6634b4..36a2e5b 100644 --- a/beesdoo_shift/wizard/holiday.py +++ b/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)