跳至内容
菜单
此问题已终结
2 回复
3403 查看

Hello,

I'm using Odoo community edition version 16. I would like to limit contact visibility like it is done for leads (In user settings I just select "User: Own Documents Only"). I would like to do the same but for Customers.

I search the web (and this forum) and fount a Record Rules mechanism. Unfortunately in my case it doesn't work well. I try to prepare a rules like "Personal Leads" and "All Leads", but for Contact model - but it doesn't work. I think there is a conflict with "res.partner.rule.private.employee". I tried to resolve it, but I broke the whole system, and need to restore database to fix it :/

How to limit the contact visibility for some users (maybe in Odoo 16 there is an easier way)?

形象
丢弃
编写者 最佳答案

Hi, Thank you for the answer, but it's a bit to detailed for me (I'm an Odoo beginner)

Where should I put all this xml statements? I an addons directory there is a "contacts" directory, but I can't find there similar lines. Should I create a new file or a new addon?

What is security group? Is it a group like "User: Own Documents Only" or "Internal User"?

What is the "module"? (As I understand the "model" is a database name, and a filed in developer mode Record Rule)


Ok, I think I got a solution. I have to deactivate private record rule for internal users and assign user as it's own salesperson in contacts. Now it seems to work...

形象
丢弃

Whenever i try your solution, the user cant log in because this error : Due to security restrictions, you are not allowed to access 'User' (res.users) records.

Records: user1 (id=11)
User: user1 (id=11)

This restriction is due to the following rules:

Contact your administrator to request access if necessary.

Implicitly accessed through 'User' (res.users).

最佳答案

Hi,

By following these steps you can create a new rule for the partners.

1. Hope you have a module category for the module to add the security groups.

eg:

<record id="module_module_name" model="ir.module.category">
        <field name="name">Module Name</field>
        <field name="description">Access for Module Name</field>
        <field name="sequence">50</field>
 </record>

2. The next step is to create the security group. You can refer to the code below.

<record id="module_name_own_documents" model="res.groups">
        <field name="name">Own Timesheets Only</field>
        <field name="category_id" ref="your category id"/>
</record>

3. Next, add access rights for the newly created group in your security file.

eg: 

access_model_name_own_documents,access.model.name.own.documents,model_model_name,module_name_own_documents,1,1,1,0 

4. Add a field in your model for the user of the corresponding employee.

user_id = fields.Many2one('res.users', string='User',related='partner_id.user_id',help='The user of the partner')

5. And last, create the rule for viewing and creating own documents.

<record id="model_name_rule_user" model="ir.rule">
    <field name="name">Model Name: Own Records</field>
    <field name="model_id" ref="model_model_name"/>
    <field name="domain_force">[('user_id', '=', user.id)]</field>
    <field name="groups" eval="[(4, ref('module_name.user_group'))]"/>
</record>


Regards

形象
丢弃
相关帖文 回复 查看 活动
1
5月 24
2221
2
10月 23
5479
2
6月 25
1202
2
5月 25
818
1
9月 24
3256