[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) <ltu@odoo.com>
Signed-off-by: Larcin Vincent (vila) <vila@odoo.com>
This commit is contained in:
Vincent Larcin
2022-06-16 17:27:16 +02:00
parent fa2082de8b
commit d9342a9c4d
+17 -21
View File
@@ -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')