Bonjour,
je souhaite restreindre la catégorie d'articles à certains utilisateurs ,pour cela j'ai créé un champ dans le modèle res.users [user_products_ids]
J'ai créé 2 règles sur les enregistrements pour les 2 modèles [product.template], [product.category]
La fonctionnalité fonctionne très bien sauf que si j'ai une sous-catégorie et que la catégorie mère est restreinte, j'ai une erreur qui apparaît:

Nom : Dessin sans titre(3).jpg
Affichages : 250
Taille : 18,5 Ko


Voici mon code :
security.xml

Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="group_restrict_product" model="res.groups">
            <field name="name">Restrict Products</field>
        </record>
 
        <record id="filter_user_product_allowed" model="ir.rule">
            <field name="name">Filter Product Allowed</field>
            <field name="model_id" ref="product.model_product_template"/>
            <field name="groups" eval="[(4, ref('group_restrict_product'))]"/>
            <field name="domain_force">[('categ_id','in', [ p.id for p in user.user_product_ids ])]</field>
 
        </record>
             <record id="filter_user_product_category_allowed" model="ir.rule">
            <field name="name">Restriction sur categorie d'article</field>
            <field name="model_id" ref="product.model_product_category"/>
            <field name="groups" eval="[(4, ref('group_restrict_product'))]"/>
            <field name="domain_force">[('id','in', [ p.id for p in user.user_product_ids ])]</field>
 
        </record>
 
    </data>
</odoo>

models.py

Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
from odoo import models, fields, api
from odoo.exceptions import Warning
 
class ResUsers(models.Model):
    _inherit = 'res.users'
 
    user_product_ids = fields.Many2many(
        'product.category',
        'product_user_rel',
        'user_id',
        'product_category_id',
        'Allowd Products')

user_view.xml
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="view_allowed_products_users_form" model="ir.ui.view">
            <field name="name">user_product_restriction.users.form</field>
            <field name="model">res.users</field>
            <field name="inherit_id" ref="base.view_users_form"/>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="Allowed Products" attrs="{'invisible': [('name', '==', 'Administrator')]}">
                        <group>
                            <field name="user_product_ids" nolabel="1" colspan="2"/>
                        </group>
                    </page>
                </notebook>
            </field>
        </record>
    </data>
</openerp>

Merci d'avence pour votre aide