Hello,
I am encountering a persistent validation error while trying to customize the res.users form view in my custom module for Odoo 17 and 18. The error message is:
Validation Error
Error while parsing or validating view:
Element '<xpath expr="//field[@name='groups_id']">' cannot be located in parent view
Details:
- I am attempting to inherit the base.view_users_form view to manage user types (e.g., Seller, Customer) for each user, specifically within the Access Rights tab of the user form. My goal is to ensure that each user has only one user type per page, avoiding the "The user cannot have more than one user types" error.
- The XPath expression //field[@name='groups_id'] is intended to target the existing groups_id field to customize the selection of user types, but it fails to locate it in the parent view.
Parent View Structure (base.view_users_form):
The groups_id field is located within <page name="access_rights"> in the notebook, as shown below:
<page name="access_rights" string="Access Rights">
<group string="Multi Companies" invisible="companies_count <= 1">
<field string="Allowed Companies" name="company_ids" widget="many2many_tags" options="{'no_create': True, 'color_field': 'color'}"/>
<field string="Default Company" name="company_id" context="{'user_preference': 0}"/>
<field string="Companies count" name="companies_count" invisible="1"/>
</group>
<field name="groups_id"/>
</page>
- Despite this, the XPath fails, suggesting the field might not be directly accessible or its context has changed in Odoo 17/18.
- Attempts Made:
- Used //page[@name='access_rights']/field[@name='groups_id'] and //page[@name='access_rights'] to target the field, but the error persists.
- Disabled manual group selection in the upper User types? section by setting invisible="1" on groups_id, but the issue remains when saving the form, especially when switching between user types per user page.
Custom View Code:
<record id="view_users_form_inherit_seller" model="ir.ui.view">
<field name="name">res.users.form.inherit.seller</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='groups_id']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//page[@name='access_rights']" position="inside">
<group name="user_type_group" string="User Type">
<field name="groups_id" widget="radio" options="{'horizontal': true}" groups="base.group_system"
domain="[('category_id.name', '=', 'User types')]"
nolabel="1"/>
<field name="user_type" widget="selection" options="{'no_create': True}" groups="base.group_system">
<option value="customer">Customer</option>
<option value="seller">Marketplace Seller</option>
</field>
</group>
</xpath>
</field>
</record>
Questions:
- Has the structure or accessibility of the groups_id field changed in Odoo 17 or 18, making it unavailable for inheritance with the specified XPath to manage user types per user page?
- Is there a recommended way to override or extend the groups_id field to enforce a single user type selection per user page without this error?
Any guidance, updated XPath syntax, or confirmation of a potential bug would be greatly appreciated. Thank you!
Any guidance or updated XPath syntax Thank you!
Odoo Version: 17 and 18