mirror of
https://github.com/bringout/oca-ocb-project.git
synced 2026-04-20 10:02:02 +02:00
19.0 vanilla
This commit is contained in:
parent
a2f74aefd8
commit
4a4d12c333
844 changed files with 212348 additions and 270090 deletions
|
|
@ -1,11 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from .test_project_base import TestProjectCommon
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestProjectConfig(TestProjectCommon):
|
||||
"""Test module configuration and its effects on projects."""
|
||||
|
|
@ -13,49 +7,120 @@ class TestProjectConfig(TestProjectCommon):
|
|||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestProjectConfig, cls).setUpClass()
|
||||
cls.Project = cls.env["project.project"]
|
||||
cls.Settings = cls.env["res.config.settings"]
|
||||
cls.features = (
|
||||
# Pairs of associated (config_flag, project_flag)
|
||||
("group_subtask_project", "allow_subtasks"),
|
||||
("group_project_recurring_tasks", "allow_recurring_tasks"),
|
||||
("group_project_rating", "rating_active"),
|
||||
)
|
||||
cls.user_settings_project_manager = cls.env['res.users.settings']._find_or_create_for_user(cls.user_projectmanager)
|
||||
cls.user_settings_project_user = cls.env['res.users.settings']._find_or_create_for_user(cls.user_projectuser)
|
||||
|
||||
# Start with a known value on feature flags to ensure validity of tests
|
||||
cls._set_feature_status(is_enabled=False)
|
||||
|
||||
@classmethod
|
||||
def _set_feature_status(cls, is_enabled):
|
||||
"""Set enabled/disabled status of all optional features in the
|
||||
project app config to is_enabled (boolean).
|
||||
def test_project_stages_feature_enable_views(self):
|
||||
"""Check that the Gantt, Calendar and Activities views are
|
||||
enabled when the 'Project Stage' feature is enabled.
|
||||
"""
|
||||
features_config = cls.Settings.create(
|
||||
{feature[0]: is_enabled for feature in cls.features})
|
||||
features_config.execute()
|
||||
self.Settings.create({"group_project_stages": True}).execute() # enabling feature
|
||||
menu_ids = set([self.env.ref('project.menu_projects').id, self.env.ref('project.menu_projects_config').id])
|
||||
menu_loaded = set(self.env['ir.ui.menu']._load_menus_blacklist())
|
||||
self.assertTrue(menu_ids.issubset(menu_loaded), "The menu project and menu projects config should be loaded")
|
||||
|
||||
def test_existing_projects_enable_features(self):
|
||||
"""Check that *existing* projects have features enabled when
|
||||
the user enables them in the module configuration.
|
||||
def test_copy_project_manager_embedded_config_as_default(self):
|
||||
"""
|
||||
self._set_feature_status(is_enabled=True)
|
||||
for config_flag, project_flag in self.features:
|
||||
self.assertTrue(
|
||||
self.project_pigs[project_flag],
|
||||
"Existing project failed to adopt activation of "
|
||||
f"{config_flag}/{project_flag} feature")
|
||||
Test that when a user gets the embedded actions configs of a projet, he gets the configs of
|
||||
the project manager as default if he has no personal configuration yet for a particular action.
|
||||
The configs he gets should also be copied in its user's settings.
|
||||
"""
|
||||
project = self.env['project.project'].create({
|
||||
'name': 'Test Project',
|
||||
'user_id': self.user_projectmanager.id,
|
||||
})
|
||||
project_action = self.env['ir.actions.act_window'].create({
|
||||
'name': 'Test Project Action',
|
||||
'res_model': 'project.project',
|
||||
})
|
||||
# Create the embedded action config for the project manager
|
||||
project_manager_config = self.env['res.users.settings.embedded.action'].create({
|
||||
'user_setting_id': self.user_settings_project_manager.id,
|
||||
'action_id': project_action.id,
|
||||
'res_model': 'project.project',
|
||||
'res_id': project.id,
|
||||
'embedded_actions_order': 'false,3,2,1',
|
||||
'embedded_actions_visibility': '1,2,3',
|
||||
'embedded_visibility': True,
|
||||
})
|
||||
|
||||
def test_new_projects_enable_features(self):
|
||||
"""Check that after the user enables features in the module
|
||||
configuration, *newly created* projects have those features
|
||||
enabled as well.
|
||||
# The project user has no personal configuration yet
|
||||
self.assertFalse(self.user_settings_project_user.embedded_actions_config_ids)
|
||||
# He should get the project manager configuration as default
|
||||
project_user_config = self.user_settings_project_user.with_context(
|
||||
res_model='project.project',
|
||||
res_id=project.id,
|
||||
).get_embedded_actions_settings()
|
||||
self.assertDictEqual(
|
||||
project_user_config[f'{project_action.id}+{project.id}'],
|
||||
{
|
||||
'embedded_actions_order': [False, 3, 2, 1],
|
||||
'embedded_actions_visibility': [1, 2, 3],
|
||||
'embedded_visibility': True,
|
||||
},
|
||||
)
|
||||
|
||||
# Check that the config has indeed been copied for the project user
|
||||
project_user_config = self.user_settings_project_user.embedded_actions_config_ids
|
||||
self.assertEqual(len(project_user_config), 1, 'There should be one embedded action setting created.')
|
||||
self.assertEqual(project_user_config.action_id, project_manager_config.action_id, 'The action should match the one set in the project manager config.')
|
||||
self.assertEqual(project_user_config.res_id, project_manager_config.res_id, 'The res_id should match the one set in the project manager config.')
|
||||
self.assertEqual(project_user_config.res_model, project_manager_config.res_model, 'The res_model should match the one set in the project manager config.')
|
||||
self.assertEqual(project_user_config.embedded_actions_order, project_manager_config.embedded_actions_order, 'The embedded actions order should match the one set in the project manager config.')
|
||||
self.assertEqual(project_user_config.embedded_actions_visibility, project_manager_config.embedded_actions_visibility, 'The embedded actions visibility should match the one set in the project manager config.')
|
||||
self.assertEqual(project_user_config.embedded_visibility, project_manager_config.embedded_visibility, 'The embedded visibility should match the one set in the project manager config.')
|
||||
|
||||
def test_no_copy_project_manager_embedded_config_as_default(self):
|
||||
"""
|
||||
self._set_feature_status(is_enabled=True)
|
||||
project_cows = self.Project.create({
|
||||
"name": "Cows",
|
||||
"partner_id": self.partner_1.id})
|
||||
for config_flag, project_flag in self.features:
|
||||
self.assertTrue(
|
||||
project_cows[project_flag],
|
||||
f"Newly created project failed to adopt activation of "
|
||||
f"{config_flag}/{project_flag} feature")
|
||||
Test that when a user gets the embedded actions configs of a projet, he does not get the configs of
|
||||
the project manager as default if he already has a personal configuration for some actions.
|
||||
"""
|
||||
project = self.env['project.project'].create({
|
||||
'name': 'Test Project',
|
||||
'user_id': self.user_projectmanager.id,
|
||||
})
|
||||
project_action = self.env['ir.actions.act_window'].create({
|
||||
'name': 'Test Project Action',
|
||||
'res_model': 'project.project',
|
||||
})
|
||||
# Create the embedded action config for the project manager
|
||||
self.env['res.users.settings.embedded.action'].create({
|
||||
'user_setting_id': self.user_settings_project_manager.id,
|
||||
'action_id': project_action.id,
|
||||
'res_model': 'project.project',
|
||||
'res_id': project.id,
|
||||
'embedded_actions_order': 'false,3,2,1',
|
||||
'embedded_actions_visibility': '1,2,3',
|
||||
'embedded_visibility': True,
|
||||
})
|
||||
# The project user already has a personal configuration
|
||||
user_config = self.env['res.users.settings.embedded.action'].create({
|
||||
'user_setting_id': self.user_settings_project_user.id,
|
||||
'action_id': project_action.id,
|
||||
'res_model': 'project.project',
|
||||
'res_id': project.id,
|
||||
'embedded_actions_order': 'false,1,2,3',
|
||||
'embedded_actions_visibility': '2,3',
|
||||
'embedded_visibility': False,
|
||||
})
|
||||
self.assertEqual(len(self.user_settings_project_user.embedded_actions_config_ids), 1)
|
||||
|
||||
# He should get his personal configuration as default
|
||||
project_user_config = self.user_settings_project_user.with_context(
|
||||
res_model='project.project',
|
||||
res_id=project.id,
|
||||
).get_embedded_actions_settings()
|
||||
self.assertDictEqual(
|
||||
project_user_config[f'{project_action.id}+{project.id}'],
|
||||
{
|
||||
'embedded_actions_order': [False, 1, 2, 3],
|
||||
'embedded_actions_visibility': [2, 3],
|
||||
'embedded_visibility': False,
|
||||
},
|
||||
)
|
||||
|
||||
# Check that no new config has been created for the project user
|
||||
project_user_config = self.user_settings_project_user.embedded_actions_config_ids
|
||||
self.assertEqual(len(project_user_config), 1, 'There should still be only one embedded action setting created.')
|
||||
self.assertEqual(project_user_config, user_config, 'The existing user config should be unchanged.')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue