How can I inherit these views to add groups="base.group_portal,base.group_user"?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Knjigovodstvo
- Zaloga
- PoS
- Projekt
- MRP
This question has been flagged
1
Odgovori
100
Prikazi
Hi,
To inherit a Qweb view in Odoo and add a groups attribute to a specific element, you need to create a custom module with an XML file. This XML file will contain an ir.ui.view record that inherits from the target Qweb template, such as website_sale.product. The inheritance is defined using the inherit_id attribute, pointing to the external ID of the original view.
Within this inheritance template, an xpath expression is used to precisely locate the HTML element you wish to modify. The position="attributes" directive is crucial here, as it tells Odoo to modify the attributes of the found element rather than its content. Subsequently, an <attribute name="groups"> tag is used to assign the desired group IDs (e.g., base.group_portal,base.group_user) to the element, thereby controlling its visibility based on user access rights.
Sample code:
<odoo>
<data>
<template id="my_custom_product_qweb_inherit" inherit_id="website_sale.product" name="Product Page Qweb Inheritance - Add Groups">
<xpath expr="//div[hasclass('oe_product_price')]" position="attributes">
<attribute name="groups">base.group_portal,base.group_user</attribute>
</xpath>
<!-- If you want to target a specific element by ID, for instance: -->
<!-- <xpath expr="//div[@id='product_description_short']" position="attributes">
<attribute name="groups">base.group_portal,base.group_user</attribute>
</xpath> -->
<!-- If you want to add a new element with groups, you would use 'after' or 'before' position and define the new element -->
<!-- <xpath expr="//div[hasclass('oe_product_price')]" position="after">
<div groups="base.group_portal,base.group_user">
<p>This content is only visible to portal and internal users.</p>
</div>
</xpath> -->
</template>
</data>
</odoo>
Finally, ensure your custom module's __manifest__.py file includes this new XML file in its data list and that the module depends on website_sale. After these changes, upgrading your custom module in Odoo will apply the inheritance, making the specified element visible only to users belonging to the defined groups.
Hope it helps
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Prijavi| Related Posts | Odgovori | Prikazi | Aktivnost | |
|---|---|---|---|---|
|
|
2
mar. 16
|
4324 | ||
|
|
1
avg. 23
|
2506 | ||
|
|
1
mar. 24
|
5720 | ||
|
|
1
sep. 21
|
10889 | ||
|
|
0
apr. 20
|
4362 |
Hello,
Can you tell the exact place where you want to add groups?
@Codesphere Tech
The highlighted.
<t t-set="product_variant_id" t-value="product._get_first_possible_variant_id()"/>
and
<form t-if="product._is_add_to_cart_possible()">
Hello
<xpath expr="//form[@t-if='product._is_add_to_cart_possible()']" position="attributes">
<attribute name="groups">base.group_portal,base.group_user</attribute>
</xpath>
Hope it helps to you.
I didn't find second view in Odoo 18..
Thanks.