İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
12448 Görünümler

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.

Avatar
Vazgeç
En İyi Yanıt

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")

Avatar
Vazgeç
En İyi Yanıt

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.

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Tem 18
1638
2
Ağu 22
3506
1
Ağu 22
2640
1
May 25
1404
2
Mar 25
5828