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

Hello Everyone,


We were looking into the ability to restrict a user so that they may create a person (contact) within a company contact record but not create an entire new company. So far all we can find  is the ability to restrict a user from creating a contact in general.

Is this possible? If so, how would we be able to accomplish this?

Thank you for any help.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can't use Access Rules / Security Groups as both an Individual and a Company are stored in the same model.


This example tests to see if the user is a member of the Sales Manager group, and if not, restricts saving if the record is not an individual:



 

Create an AUTOMATED action for the res.partner model that is triggered on CREATE of res.partner:





The Server Action would be defined something like this:


if not env.user.has_group('base.group_sale_manager') and record.company_type != 'person':
    raise Warning("You can't do that")

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

While it's entirely possible to implement it as Ray Carnes has done (As a bonus it even gives you the ability to raise a custom warning, rather than the generic permission denied message, which is why I prefer his method), I just wanted to show that a rule like this can easily be implemented through the access rules.


While individuals and companies are the same model, you can restrict CRUD permissions on a model by domain filtering. Therefore we can give Create/Delete permission to a group only when the is_company field is false.


(Using v11, though similar for v9/10)


In Settings -> Users & Companies (Users in v9-10) -> Groups -> Extra Rights /  Contact Creation -> Rules -> Edit -> Add an Item -> Create

From here you can create a rule. 

Object: res.partner

Access Rights: Create (And possibly delete, depends on your needs)

Rule definition: [('is_company', '=', False)]

Groups: Extra Rights / Contact Creation


Note: if another rule exists regarding res.model models, things get a little trickier. Read the "Interaction between rules" section on the creation menu for more information.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.ค. 18
1638
Limit visibility of contacts to users. แก้ไขแล้ว
2
ส.ค. 22
3764
1
ส.ค. 22
2908
1
พ.ค. 25
1800
2
มี.ค. 25
6127