Browse Source

Fix singleton exception for res_users.py

This exception is raised, when:
```
    rslt = super().write(vals)
  File "/custom_addons/hide_menu_user/models/res_users.py", line 37, in write
    menu.restrict_user_ids = [fields.Command.link(self.id)]
  File "/opt/prod-odoo17/odoo/fields.py", line 5140, in __get__
    raise ValueError("Expected singleton: %s" % record)
ValueError: Expected singleton: res.users(2, 46, 41, 43, 44, 48, 8, 40, 39, 47, 7, 49, 6, 45, 42, 9)

```
pull/317/head
Paulius 1 year ago
committed by GitHub
parent
commit
99b046a2f8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      hide_menu_user/models/res_users.py

10
hide_menu_user/models/res_users.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################# #############################################################################
from odoo import fields, models from odoo import fields, models, Command
class ResUsers(models.Model): class ResUsers(models.Model):
@ -30,14 +30,14 @@ class ResUsers(models.Model):
def write(self, vals): def write(self, vals):
""" """
Write method for the ResUsers model. Write method for the ResUsers model.
Ensure the menu will not remain hidden after removing it from the list. Ensure the menu will not remain hidden after removing it from the list.
""" """
res = super(ResUsers, self).write(vals) res = super(ResUsers, self).write(vals)
for record in self: for record in self:
for menu in record.hide_menu_ids: for menu in record.hide_menu_ids:
menu.write({ menu.write({
'restrict_user_ids': [fields.Command.link(record.id)] 'restrict_user_ids': [Command.set([record.id] + [user.id for user in menu.restrict_user_ids])]
}) })
return res return res

Loading…
Cancel
Save