From 6640ab1425fa522e6c9e1f82e7ebf2d9c6eaee49 Mon Sep 17 00:00:00 2001 From: nicolasjamoulle Date: Mon, 11 Mar 2019 15:26:28 +0100 Subject: [PATCH 1/6] [FIX] Remove shifts for resigning status And does not allow to add unsubscribed and resigning statut to a new shift --- beesdoo_shift/models/cooperative_status.py | 2 +- beesdoo_shift/views/task.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index 811adee..757937b 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -221,7 +221,7 @@ class CooperativeStatus(models.Model): if self.working_mode != 'irregular': #Don't reset alert time for irregular data['alert_start_time'] = False self.write(data) - if new_state == 'unsubscribed': + if new_state == 'unsubscribed' or new_state == 'resigning': self.cooperator_id.sudo().write({'subscribed_shift_ids' : [(5,0,0)]}) #TODO: Add one day othertwise unsubscribed from the shift you were absent self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today([self.cooperator_id.id], today=self.today) diff --git a/beesdoo_shift/views/task.xml b/beesdoo_shift/views/task.xml index 7c397da..442bfda 100644 --- a/beesdoo_shift/views/task.xml +++ b/beesdoo_shift/views/task.xml @@ -97,8 +97,8 @@ - - + + Date: Tue, 12 Mar 2019 10:16:25 +0100 Subject: [PATCH 2/6] [ADD] remove super_coop_id --- beesdoo_shift/models/task.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 91345b4..226f154 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -81,6 +81,9 @@ class Task(models.Model): 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}) + # if self.super_coop_id.id: + # to_unsubscribe_replace.write({'super_coop_id': False}) + @api.multi def write(self, vals): """ From 95c16bc6d4f3bcace23144618e61cfa6fe9f5b9c Mon Sep 17 00:00:00 2001 From: nicolasjamoulle Date: Tue, 12 Mar 2019 14:44:08 +0100 Subject: [PATCH 3/6] [WIP] Tests in comment --- beesdoo_shift/models/task.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 226f154..a97811b 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -82,7 +82,11 @@ class Task(models.Model): to_unsubscribe_replace.write({'worker_id': False, 'is_regular': False, 'replaced_id': False}) # if self.super_coop_id.id: - # to_unsubscribe_replace.write({'super_coop_id': False}) + # to_unsubscribe_super_coop = self.search([('super_coop_id', 'in', + # self.super_coop_id.id)] + # + date_domain) + # to_unsubscribe_super_coop.write({'super_coop_id': False, + # 'is_regular': False}) @api.multi def write(self, vals): From 120de0499f18c7c0682bc6abe930e07db7bb686f Mon Sep 17 00:00:00 2001 From: nicolasjamoulle Date: Tue, 19 Mar 2019 11:33:18 +0100 Subject: [PATCH 4/6] [ADD] Remove super cooperative from future planning --- beesdoo_shift/models/task.py | 17 +++++++++++------ beesdoo_shift/wizard/subscribe.py | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index a97811b..a915a77 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -81,12 +81,17 @@ class Task(models.Model): 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}) - # if self.super_coop_id.id: - # to_unsubscribe_super_coop = self.search([('super_coop_id', 'in', - # self.super_coop_id.id)] - # + date_domain) - # to_unsubscribe_super_coop.write({'super_coop_id': False, - # 'is_regular': False}) + # If worker is Super cooperative, remove it + super_coop_id = self.env['res.users'].search( + [('partner_id', '=', worker_ids[0]), ('super', '=', True)]).id + + if super_coop_id: + to_unsubscribe_super_coop = self.search([('super_coop_id', '=', + super_coop_id), + ('start_time', '>=', + today)]) + to_unsubscribe_super_coop.write({'super_coop_id': False, + 'is_regular': False}) @api.multi def write(self, vals): diff --git a/beesdoo_shift/wizard/subscribe.py b/beesdoo_shift/wizard/subscribe.py index b72a13a..9d2be66 100644 --- a/beesdoo_shift/wizard/subscribe.py +++ b/beesdoo_shift/wizard/subscribe.py @@ -81,7 +81,7 @@ class Subscribe(models.TransientModel): data = { 'unsubscribed': True, 'cooperator_id': self.cooperator_id.id, - 'resigning' : self.resigning, + 'resigning': self.resigning, } if status_id: status_id.sudo().write(data) From 276a50d88386f05043ac7f42ae629077d7ab46eb Mon Sep 17 00:00:00 2001 From: nicolasjamoulle Date: Tue, 19 Mar 2019 16:05:47 +0100 Subject: [PATCH 5/6] [REF] date_domain and to_unsubscribe_super_coop --- beesdoo_shift/models/task.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index a915a77..3f15a3b 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -70,7 +70,8 @@ class Task(models.Model): today += ' 00:00:00' if end_date: end_date += ' 23:59:59' - date_domain = [('worker_id', 'in', worker_ids), ('start_time', '>=', today)] + # date_domain = [('worker_id', 'in', worker_ids), ('start_time', '>=', today)] + date_domain = [('start_time', '>=', today)] if end_date: date_domain.append(('end_time', '<=', end_date)) to_unsubscribe = self.search([('worker_id', 'in', worker_ids)] + date_domain) @@ -81,15 +82,14 @@ class Task(models.Model): 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}) - # If worker is Super cooperative, remove it + # If worker is Super cooperative, remove it from planning super_coop_id = self.env['res.users'].search( - [('partner_id', '=', worker_ids[0]), ('super', '=', True)]).id + [('partner_id', 'in', worker_ids), ('super', '=', True)]).ids if super_coop_id: - to_unsubscribe_super_coop = self.search([('super_coop_id', '=', - super_coop_id), - ('start_time', '>=', - today)]) + to_unsubscribe_super_coop = self.search([('super_coop_id', 'in', + super_coop_id)] + + date_domain) to_unsubscribe_super_coop.write({'super_coop_id': False, 'is_regular': False}) From d0df069801160f237d028d37b5ad69cc437edddd Mon Sep 17 00:00:00 2001 From: nicolasjamoulle Date: Sat, 23 Mar 2019 09:37:34 +0100 Subject: [PATCH 6/6] Makeup on code after review --- beesdoo_shift/models/task.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 3f15a3b..784d749 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -82,14 +82,13 @@ class Task(models.Model): 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}) - # If worker is Super cooperative, remove it from planning - super_coop_id = self.env['res.users'].search( + # If worker is Super cooperator, remove it from planning + super_coop_ids = self.env['res.users'].search( [('partner_id', 'in', worker_ids), ('super', '=', True)]).ids - if super_coop_id: - to_unsubscribe_super_coop = self.search([('super_coop_id', 'in', - super_coop_id)] + - date_domain) + if super_coop_ids: + to_unsubscribe_super_coop = self.search( + [('super_coop_id', 'in', super_coop_ids)] + date_domain) to_unsubscribe_super_coop.write({'super_coop_id': False, 'is_regular': False})