Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion addons/hr/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
'km_home_work',
'marital',
'mobile_phone',
'notes',
'employee_parent_id',
'passport_id',
'permit_no',
Expand Down
14 changes: 14 additions & 0 deletions addons/hr/tests/test_self_user_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,17 @@ def test_access_employee_account(self):

hubert_acc.invalidate_recordset(["display_name"])
self.assertEqual(hubert_emp.with_user(hubert).sudo().bank_account_id.sudo(False).display_name, 'FR******7890')

def test_onchange_readable_fields_with_no_access(self):
"""
The purpose is to test that the onchange logic takes into account `SELF_READABLE_FIELDS`.

The view contains fields that are in `SELF_READABLE_FIELDS` (example: `private_street`).
Even if the user does not have read access to the employee,
it should not cause an access error if these fields are in `SELF_READABLE_FIELDS`.
"""
self.env['res.lang']._activate_lang("fr_FR")
with Form(self.richard.with_user(self.richard), view='hr.res_users_view_form_profile') as form:
# triggering an onchange should not trigger some access error
form.lang = "fr_FR"
form.tz = "Europe/Brussels"
7 changes: 7 additions & 0 deletions odoo/addons/base/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ def toggle_active(self):
user.partner_id.toggle_active()
super(Users, self).toggle_active()

def onchange(self, values, field_names, fields_spec):
# Hacky fix to access fields in `SELF_READABLE_FIELDS` in the onchange logic.
# Put field values in the cache.
if self == self.env.user:
[self.sudo()[field_name] for field_name in self.SELF_READABLE_FIELDS]
return super().onchange(values, field_names, fields_spec)

def read(self, fields=None, load='_classic_read'):
if fields and self == self.env.user:
readable = self.SELF_READABLE_FIELDS
Expand Down
2 changes: 2 additions & 0 deletions odoo/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,8 @@ def _init_from_defaults(self, model):
self._changed.update(self._view['fields'])

def _init_from_values(self, values):
self._env.flush_all()
self._env.clear() # discard cache and pending recomputations
self._values.update(
record_to_values(self._view['fields'], values))

Expand Down