コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
2707 ビュー

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

アバター
破棄
最善の回答

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>
アバター
破棄
関連投稿 返信 ビュー 活動
0
8月 21
3430
1
11月 24
1522
0
8月 21
2402
1
6月 19
4306