From d9342a9c4de424af700bedab52ca8bed96e54149 Mon Sep 17 00:00:00 2001 From: Vincent Larcin Date: Fri, 3 Jun 2022 07:54:36 +0000 Subject: [PATCH] [FIX] project: disable basic features on all projects Steps to reproduce ------------------ 1. Install project and fsm. 2. Enable a basic project feature (sub-tasks/task dependencies) in the settings. 3. Enable the same feature on the fsm project. 4. Disable the feature in the settings. 5. The feature is still enabled on the fsm project - This can be hard to see since the field will be hidden on the settings of the project, but you can see that the "Sub-tasks" tab is still visible on tasks if you enabled sub-tasks. - Also, when re-enabling the feature globally, it should be disabled for the fsm project, but won't be. Expected behavior ----------------- The feature should be disabled on all projects, including fsm ones, when disabling it globally --- This commit fixes this bug by selecting all projects, and not just basic ones, when disabling a basic feature globally, to disable that feature on all projects. Related: https://github.com/odoo/enterprise/pull/28036 Task-2871448 closes odoo/odoo#93820 X-original-commit: 84f8957533e85672d3b17d1a9004193b091f9fea Related: odoo/enterprise#28488 Signed-off-by: Laurent Stukkens (ltu) Signed-off-by: Larcin Vincent (vila) --- addons/project/models/res_config_settings.py | 38 +++++++++----------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/addons/project/models/res_config_settings.py b/addons/project/models/res_config_settings.py index 93ebc05699a..0a6532cf9c1 100644 --- a/addons/project/models/res_config_settings.py +++ b/addons/project/models/res_config_settings.py @@ -35,30 +35,26 @@ class ResConfigSettings(models.TransientModel): def set_values(self): # Ensure that settings on existing projects match the above fields projects = self.env["project.project"].search([]) - global_features = { # key: config_flag, value: project_flag - "group_project_rating": "rating_active", - "group_project_recurring_tasks": "allow_recurring_tasks", - } - basic_project_features = { - "group_subtask_project": "allow_subtasks", - "group_project_task_dependencies": "allow_task_dependencies", - 'group_project_milestone': 'allow_milestones', - } - config_feature_vals = {config_flag: self[config_flag] - for config_flag in global_features.keys() | basic_project_features.keys()} + basic_projects = projects.filtered_domain(self._get_basic_project_domain()) - def update_projects(projects, features): - for (config_flag, project_flag) in features.items(): - config_flag_global = "project." + config_flag - config_feature_enabled = config_feature_vals[config_flag] - if self.user_has_groups(config_flag_global) != config_feature_enabled: + features = { + # key: (config_flag, is_global), value: project_flag + ("group_project_rating", True): "rating_active", + ("group_project_recurring_tasks", True): "allow_recurring_tasks", + ("group_subtask_project", False): "allow_subtasks", + ("group_project_task_dependencies", False): "allow_task_dependencies", + ("group_project_milestone", False): "allow_milestones", + } + + for (config_flag, is_global), project_flag in features.items(): + config_flag_global = f"project.{config_flag}" + config_feature_enabled = self[config_flag] + if self.user_has_groups(config_flag_global) != config_feature_enabled: + if config_feature_enabled and not is_global: + basic_projects[project_flag] = config_feature_enabled + else: projects[project_flag] = config_feature_enabled - # update for all projects - update_projects(projects, global_features) - # update for basic projects - update_projects(projects.filtered_domain(self._get_basic_project_domain()), basic_project_features) - # Hide the task dependency changes subtype when the dependency setting is disabled task_dep_change_subtype_id = self.env.ref('project.mt_task_dependency_change') project_task_dep_change_subtype_id = self.env.ref('project.mt_project_task_dependency_change')