[IMP] project: add default personnal stage to user

Currently, when a db is loaded without demo data, or that a user has no
task assigned and no personnal stage, the view 'My tasks' is empty. The
purpose of this commit is to assign default personnal stage to a user in
these case to ease the understanding of new user of what the view can be
used for.

This commit :
- add default personnal stage to user the first time he clicks on the
'My tasks' menu if the user has no personnal stage and no task are assigned
to him.

task-3047496

closes odoo/odoo#105940

Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
damr
2022-12-15 13:40:40 +01:00
parent 2bd71d2c9e
commit 9c5d7adf3d
3 changed files with 41 additions and 1 deletions
+9
View File
@@ -2373,6 +2373,15 @@ class Task(models.Model):
res.update(super(Task, leftover)._notify_get_reply_to(default=default))
return res
def _ensure_personal_stages(self):
user = self.env.user
ProjectTaskTypeSudo = self.env['project.task.type'].sudo()
# In the case no stages have been found, we create the default stages for the user
if not ProjectTaskTypeSudo.search_count([('user_id', '=', user.id)], limit=1):
ProjectTaskTypeSudo.with_context(lang=user.lang, default_project_id=False).create(
self.with_context(lang=user.lang)._get_default_personal_stage_create_vals(user.id)
)
def email_split(self, msg):
email_list = tools.email_split((msg.get('to') or '') + ',' + (msg.get('cc') or ''))
# check left-part is not already an alias
@@ -90,6 +90,28 @@ class TestPersonalStages(TestProjectCommon):
self.assertEqual(1, total_stage_0)
self.assertEqual(1, total_stage_1)
def test_default_personal_stage(self):
user_without_stage, user_with_stages = self.env['res.users'].create([{
'login': 'test_no_stage',
'name': "Test User without stage",
}, {
'login': 'test_stages',
'name': "Test User with stages",
}])
personal_stage = self.env['project.task.type'].create({
'name': 'personal stage',
'user_id': user_with_stages.id,
})
ProjectTaskTypeSudo = self.env['project.task.type'].sudo()
# ensure that a user without personal stage is getting the default stages
self.task_1.with_user(user_without_stage)._ensure_personal_stages()
stages = ProjectTaskTypeSudo.search([('user_id', '=', user_without_stage.id)])
self.assertEqual(len(stages), 7, "As this user had no personal stage, the default ones should have been created for him")
# ensure that the user's personal stages are not changing if the user already had some
self.task_1.with_user(user_with_stages)._ensure_personal_stages()
stages = ProjectTaskTypeSudo.search([('user_id', '=', user_with_stages.id)])
self.assertEqual(stages, personal_stage, "As this user already had a personal stage, none should be added")
@tagged('-at_install', 'post_install')
class TestPersonalStageTour(HttpCase, TestProjectCommon):
+10 -1
View File
@@ -1770,8 +1770,17 @@
<field name="view_id" ref="view_task_all_calendar"/>
</record>
<record id="action_server_view_my_task" model="ir.actions.server">
<field name="name">menu view My Tasks</field>
<field name="model_id" ref="project.model_project_task"/>
<field name="state">code</field>
<field name="code">
model._ensure_personal_stages(); action = env["ir.actions.actions"]._for_xml_id("project.action_view_my_task")
</field>
</record>
<menuitem name="My Tasks" id="menu_project_management" parent="menu_main_pm"
action="action_view_my_task" sequence="2" groups="group_project_user"/>
action="action_server_view_my_task" sequence="2" groups="group_project_user"/>
<menuitem name="All Tasks" id="menu_project_management_all_tasks" parent="menu_main_pm"
action="action_view_all_task" sequence="2" groups="group_project_user"/>