From 47f453c1d405a46ef2630c3b62db6e6cb3e916bb Mon Sep 17 00:00:00 2001 From: Prakash Prajapati Date: Tue, 10 May 2022 06:08:41 +0000 Subject: [PATCH] [IMP] project: prevent assigning non-personal stages to private tasks Before this commit, it was possible to assign a non-personal stage on a private task, which is a nonsense as the task does not belong to a project. Only personal stages should be set to a private task. After this commit, if a non-personal stage is set on a private task, a UserError is raised. task-2818486 Part-of: odoo/odoo#89041 --- addons/project/models/project.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index bdc5e146981..5cc110fbe31 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -1859,6 +1859,9 @@ class Task(models.Model): vals["company_id"] = self.env["project.project"].browse( project_id ).company_id.id or self.env.company.id + if not project_id and ("stage_id" in vals or self.env.context.get('default_stage_id')): + vals["stage_id"] = False + if project_id and "stage_id" not in vals: # 1) Allows keeping the batch creation of tasks # 2) Ensure the defaults are correct (and computed once by project), @@ -1930,6 +1933,9 @@ class Task(models.Model): raise UserError(_('Archived tasks cannot be recurring. Please unarchive the task first.')) # stage change: update date_last_stage_update if 'stage_id' in vals: + if not 'project_id' in vals and self.filtered(lambda t: not t.project_id): + raise UserError(_('You can only set a personal stage on a private task.')) + vals.update(self.update_date_end(vals['stage_id'])) vals['date_last_stage_update'] = now # reset kanban state when changing stage