[FIX] hr: make 'My Profile' available again to non-HR

It was no longer possible to load the My Profile for users with an
employee that were not HR Officer.

In the `get_views()` method, the 'search' view was requested after the
'form', thus it omited the fields requested as SUPERUSER in
`get_view()`.

closes odoo/odoo#99750

Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
Kevin Baptiste
2022-09-08 10:42:44 +02:00
parent ce230f5cd9
commit 980a9f0cd6
5 changed files with 64 additions and 0 deletions
+3
View File
@@ -72,6 +72,9 @@
'hr/static/tests/m2x_avatar_employee_tests.js',
'hr/static/tests/standalone_m2o_avatar_employee_tests.js',
],
'web.assets_tests': [
'hr/static/tests/tours/hr_employee_flow.js',
],
},
'license': 'LGPL-3',
}
+14
View File
@@ -168,6 +168,20 @@ class User(models.Model):
def SELF_WRITEABLE_FIELDS(self):
return super().SELF_WRITEABLE_FIELDS + HR_WRITABLE_FIELDS
@api.model
def get_views(self, views, options=None):
# Requests the My Profile form view as last.
# Otherwise the fields of the 'search' view will take precedence
# and will omit the fields that are requested as SUPERUSER
# in `get_view()`.
profile_view = self.env.ref("hr.res_users_view_form_profile")
profile_form = profile_view and [profile_view.id, 'form']
if profile_form and profile_form in views:
views.remove(profile_form)
views.append(profile_form)
result = super().get_views(views, options)
return result
@api.model
def get_view(self, view_id=None, view_type='form', **options):
# When the front-end loads the views it gets the list of available fields
@@ -0,0 +1,29 @@
/** @odoo-module **/
import tour from 'web_tour.tour';
tour.register('hr_employee_tour', {
test: true,
url: '/web',
}, [
tour.stepUtils.showAppsMenuItem(),
{
content: "Open Employees app",
trigger: ".o_app[data-menu-xmlid='hr.menu_hr_root']",
run: 'click',
},
{
content: "Open an Employee Profile",
trigger: ".o_kanban_record_title:contains('Johnny H.')",
run: 'click',
},
{
content: "Open user account menu",
trigger: ".o_user_menu .oe_topbar_name",
run: 'click',
}, {
content: "Open My Profile",
trigger: "[data-menu=settings]",
run: 'click',
},
]);
+1
View File
@@ -6,3 +6,4 @@ from . import test_channel
from . import test_self_user_access
from . import test_multi_company
from . import test_resource
from . import test_ui
+17
View File
@@ -0,0 +1,17 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import HttpCase, tagged, new_test_user
@tagged('-at_install', 'post_install')
class TestEmployeeUi(HttpCase):
def test_employee_profile_tour(self):
user = new_test_user(self.env, login='davidelora', groups='base.group_user')
self.env['hr.employee'].create([{
'name': 'Johnny H.',
}, {
'name': 'David Elora',
'user_id': user.id,
}])
self.start_tour("/web", 'hr_employee_tour', login="davidelora")