diff --git a/beesdoo_shift/models/cooperative_status.py b/beesdoo_shift/models/cooperative_status.py index 3a241c8..cc05f8c 100644 --- a/beesdoo_shift/models/cooperative_status.py +++ b/beesdoo_shift/models/cooperative_status.py @@ -91,7 +91,7 @@ class CooperativeStatus(models.Model): comodel_name="cooperative.exempt.reason", string="Exempt Reason" ) status = fields.Selection( - selection=_get_status, + selection=lambda x: x._get_status(), compute="_compute_status", string="Cooperative Status", store=True, @@ -106,11 +106,10 @@ class CooperativeStatus(models.Model): ) # Specific to irregular - irregular_start_date = fields.Date() # TODO migration script + irregular_start_date = fields.Date() irregular_absence_date = fields.Date() - irregular_absence_counter = ( - fields.Integer() - ) # TODO unsubscribe when reach -2 + irregular_absence_counter = fields.Integer() + future_alert_date = fields.Date(compute="_compute_future_alert_date") next_countdown_date = fields.Date(compute="_compute_next_countdown_date") @@ -273,7 +272,7 @@ class CooperativeStatus(models.Model): if not journal: journal = self.env["beesdoo.shift.journal"].create({"date": today}) - domain = self._get_irregular_worker_domain(today=today) + domain = self._get_irregular_worker_domain(today) irregular = self.search(domain) for status in irregular: delta = (today - status.irregular_start_date).days @@ -362,7 +361,7 @@ class CooperativeStatus(models.Model): # Irregular Cron implementation # ############################################### - def _get_irregular_worker_domain(self): + def _get_irregular_worker_domain(self, today): """ return the domain the give the list of valid irregular worker that should diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 119f8f7..955b997 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -59,7 +59,7 @@ class Task(models.Model): ) end_time = fields.Datetime(track_visibility="always", required=True) state = fields.Selection( - selection=_get_selection_status, + selection=lambda x: x._get_selection_status(), default="open", required=True, track_visibility="onchange", @@ -96,20 +96,6 @@ class Task(models.Model): for rec in self: rec.color = self._get_color_mapping(rec.state) - def _compensation_validation(self, task): - """ - Raise a validation error if the fields is_regular and - is_compensation are not properly set. - """ - if task.is_regular == task.is_compensation or not ( - task.is_regular or task.is_compensation - ): - raise ValidationError( - _( - "You must choose between Regular Shift or " - "Compensation Shift." - ) - ) @api.constrains("state") def _lock_future_task(self): @@ -122,30 +108,6 @@ class Task(models.Model): ) ) - @api.constrains("is_regular", "is_compensation") - def _check_compensation(self): - for task in self: - if task.working_mode == "regular": - self._compensation_validation(task) - - @api.constrains("worker_id") - def _check_worker_id(self): - """ - When worker_id changes we need to check whether is_regular - and is_compensation are set correctly. - When worker_id is set to a worker that doesn't need field - is_regular and is_compensation, these two fields are set to - False. - """ - for task in self: - if task.working_mode == "regular": - self._compensation_validation(task) - else: - task.write({"is_regular": False, "is_compensation": False}) - if task.worker_id: - if task.worker_id == task.replaced_id: - raise UserError(_("A worker cannot replace himself.")) - def message_auto_subscribe(self, updated_fields, values=None): self._add_follower(values) return super(Task, self).message_auto_subscribe( diff --git a/beesdoo_shift/views/cooperative_status.xml b/beesdoo_shift/views/cooperative_status.xml index 6681b11..9dadd20 100644 --- a/beesdoo_shift/views/cooperative_status.xml +++ b/beesdoo_shift/views/cooperative_status.xml @@ -161,7 +161,7 @@ - + diff --git a/beesdoo_worker_status/models/cooperative_status.py b/beesdoo_worker_status/models/cooperative_status.py index 2b1db7c..a0fb756 100644 --- a/beesdoo_worker_status/models/cooperative_status.py +++ b/beesdoo_worker_status/models/cooperative_status.py @@ -320,8 +320,7 @@ class CooperativeStatus(models.Model): # Irregular Cron implementation # ############################################### - def _get_irregular_worker_domain(self, **kwargs): - today = kwargs.get("today") or self.today + def _get_irregular_worker_domain(self, today): return [ "&", "&", diff --git a/beesdoo_worker_status/models/task.py b/beesdoo_worker_status/models/task.py index 2e823f7..28863e4 100644 --- a/beesdoo_worker_status/models/task.py +++ b/beesdoo_worker_status/models/task.py @@ -4,6 +4,46 @@ from odoo import fields, models class Task(models.Model): _inherit = "beesdoo.shift.shift" + @api.constrains("worker_id") + def _check_worker_id(self): + """ + When worker_id changes we need to check whether is_regular + and is_compensation are set correctly. + When worker_id is set to a worker that doesn't need field + is_regular and is_compensation, these two fields are set to + False. + """ + for task in self: + if task.working_mode == "regular": + self._compensation_validation(task) + else: + task.write({"is_regular": False, "is_compensation": False}) + if task.worker_id: + if task.worker_id == task.replaced_id: + raise UserError(_("A worker cannot replace himself.")) + + def _compensation_validation(self, task): + """ + Raise a validation error if the fields is_regular and + is_compensation are not properly set. + """ + if task.is_regular == task.is_compensation or not ( + task.is_regular or task.is_compensation + ): + raise ValidationError( + _( + "You must choose between Regular Shift or " + "Compensation Shift." + ) + ) + + @api.constrains("is_regular", "is_compensation") + def _check_compensation(self): + for task in self: + if task.working_mode == "regular": + self._compensation_validation(task) + + ################################# # State Definition # #################################