0

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 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?

Odoo Version: 17 and 18​

1
  • I'm not sure if understand what's your goal here. What do you mean by user types? User types in Odoo is a special access groups category where you have to add new groups to get new selections. For example: i had to create a new user type access group for a customer for external people, which should use Odoo's backend but with more restrictions than the internal user, but less restrictions than portal users. Commented May 7 at 13:41

1 Answer 1

1

Another inherited view is probably removing/replacing the field and/or a parent element. Check the inheritance list... This view has a lot of views extending it in standard modules by the way... Look for things like <field name="groups_id" position="replace"> in the inherited views (go through the list in settings -> technical -> views).

Again, it might not be this field itself, might be a parent element, like the page or something - but that's less likely.

To be clear: the inheritance order is important, each view that inherits the original view actually modifies the contents and therefore the elements are really "gone" or "added" - potentially leading to the "Element ____ cannot be located in parent view" error.


Update: Found one in the very first inherited view... base.user_groups_view. It replaces groups_id field with a bunch of other content... (checked runbot community 18.0)

inherited view

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.