diff options
| author | Dominik Rubo <dru@odoo.com> | 2020-08-21 09:46:28 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2020-10-15 10:48:07 +0000 |
| commit | 8dd0edae898a532dbe7e4f18c9118b9b68e57900 (patch) | |
| tree | 80e5af6ddf28c117f5a4666353495e1c942ee9b7 /addons/project/models | |
| parent | 7ba0bc47d1404d5ac4bbf8cb5dcca7937558bd1a (diff) | |
[IMP] project: enable config-selected features in projects
This change ensures that when the user activates optional features of the
project app, they are enabled in existing projects as well as newly created
projects automatically, which is likely what the user expects.
For most optional features, this behavior was already in place. It was not in
place yet for the sub-tasks and timesheets features, which this change fixes.
Two added tests check the behavior described above for features that are
activated through a `group_*` field on `res.config.settings` (sub-tasks,
recurring tasks and ratings). The tests do not cover features that are
activated through a `module_*` field, as such fields require the installation
of further modules and we cannot simulate this.
Task 2297054
closes odoo/odoo#58692
Related: odoo/enterprise#13641
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Co-authored-by: Kevin Baptiste <50135801+kba-odoo@users.noreply.github.com>
Diffstat (limited to 'addons/project/models')
| -rw-r--r-- | addons/project/models/res_config_settings.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/addons/project/models/res_config_settings.py b/addons/project/models/res_config_settings.py index 1831c1cd0ca..ae12e7efb23 100644 --- a/addons/project/models/res_config_settings.py +++ b/addons/project/models/res_config_settings.py @@ -14,6 +14,20 @@ class ResConfigSettings(models.TransientModel): group_project_recurring_tasks = fields.Boolean("Recurring Tasks", implied_group="project.group_project_recurring_tasks") def set_values(self): - if self.user_has_groups('project.group_project_recurring_tasks') != self.group_project_recurring_tasks: - self.env['project.project'].sudo().search([]).write({'allow_recurring_tasks': self.group_project_recurring_tasks}) + + # Ensure that settings on existing projects match the above fields + projects = self.env["project.project"].search([]) + features = ( + # Pairs of associated (config_flag, project_flag) + ("group_subtask_project", "allow_subtasks"), + ("group_project_rating", "rating_active"), + ("group_project_recurring_tasks", "allow_recurring_tasks"), + ) + for (config_flag, project_flag) in features: + config_flag_global = "project." + config_flag + config_feature_enabled = self[config_flag] + if (self.user_has_groups(config_flag_global) + is not config_feature_enabled): + projects[project_flag] = config_feature_enabled + super(ResConfigSettings, self).set_values() |
