Ajuda

0

[Odoo 13] How to prevent certain users from seeing certain records?

Avatar
Cristian Gómez

Hello,

I'm learning Odoo 14 and I would like to have certain products which cannot be seen by normal users, only administrators can see them.

I have created a boolean field for product.template class and the idea is, when this field is true, only users belonging to administrator group for inventory model (for example) can see the product.

I have also created a record rule for it, but it doesn't seem to work. What's more, it hides the product record for all users when the boolean field is true!

Here is my code:

class ProductProduct(models.Model):
_inherit = 'product.template'

    esEstrategic = fields.Boolean('Producte Estratègic?',default=False)#boolean field for the invisibility

Record rules:

    <record model="ir.rule" id="product_esEstrategic_invisibility">
<field name="name">Productes estratègics invisibles per a usuaris normals</field>
<field name="model_id" ref="model_product_template"/>
<field name="domain_force">[('esEstrategic','=', True)]</field>
<field name="groups" eval="[(4,ref('stock.group_stock_user'))]"/>
<field name="perm_read" eval="0"/>
</record>

<record model="ir.rule" id="product_esEstrategic_visibility">
<field name="name">Productes estratègics invisibles per a usuaris normals</field>
<field name="model_id" ref="model_product_template"/>
<field name="domain_force">['|',('esEstrategic','=', True),('esEstrategic','=',False)]</field>
<field name="groups" eval="[(4,ref('stock.group_stock_manager'))]"/>
<!-- <field name="perm_read" eval="1"/>-->
</record>

Thanks in advance

Avatar
Descartar
1 Resposta
2
Avatar
Rajnish Nalawade
Melhor Resposta

create a many2many field (allowed_products) on the user form and set the product which should be allowed to inventory admin with compute function.

<record model="ir.rule" id="product_esEstrategic_invisibility">
<field name="name">Productes estratègics invisibles per a usuaris normals</field>
<field name="model_id" ref="model_product_template"/>
<field name="domain_force">[('esEstrategic','=', True),('id','in',user.allowed_products.ids)]</field>
<field name="groups" eval="[(4,ref('stock.group_stock_user'))]"/>
<field name="perm_read" eval="0"/>
</record>
Avatar
Descartar