Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
4145 มุมมอง

In a multi company setup I need to filter data by selected company. I sadly don't know how to do this with the search view because it cannot use "user". With access rules it throws the AccessError document res.partner operation create.

My access rule for res.partner: [('company_id', 'in', [user.company_id.id])]. 

How to change it so that the contacts will be filtered and one can create a record. And a contact can be created if I disable the access rule, so the user has required permissions.  

อวตาร
ละทิ้ง

Which version of Odoo?

ผู้เขียน

Odoo 10. Did not write it because I tagged it.

คำตอบที่ดีที่สุด

Hello,

Yes, you can manage this by Record rule just need minor correction on your rule.

You have to add one more domain if company_id is false 

['|', ('company_id', 'in', company_ids), ('company_id', '=', False)]

instead of this : 

rule for res.partner: [('company_id', 'in', [user.company_id.id])]. 

Why you got create access error because when you try to create contact , company id is blank at creation time no default value set on that form. so as per rule it will not allow . 

try this rule , so you can able to see his own company contact and contact on which company not set. 


อวตาร
ละทิ้ง
ผู้เขียน

it works on res.partner. Now I need to figure out why I get ValueError: Invalid field 'company_id' in leaf "<osv.ExtendedLeaf: ('company_id', '=', False) on res_company on other modules that have company_id. Maybe I need to fill it in create method and not allow selection.

คำตอบที่ดีที่สุด

I think you should define compute field (with search) and add it to search view like

has_company = fields.Boolean(compute='_compute_company', search="_search_company")

อวตาร
ละทิ้ง
ผู้เขียน

Cannot because I'm filtering this for many many models. So I cannot do that. So I need a way to do this with access rules.

Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ส.ค. 23
21461
1
ส.ค. 20
6011
2
มิ.ย. 21
6598
4
ธ.ค. 19
4718
2
ก.ค. 25
4491