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
- Contabilidad
- Inventario
- PoS
- Proyectos
- MRP
Se marcó esta pregunta
1
Responder
104
Vistas
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
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
Registrarse| Publicaciones relacionadas | Respuestas | Vistas | Actividad | |
|---|---|---|---|---|
|
|
2
mar 16
|
4326 | ||
|
|
1
ago 23
|
2509 | ||
|
|
1
mar 24
|
5723 | ||
|
|
1
sept 21
|
10891 | ||
|
|
0
abr 20
|
4363 |
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.