Skip to Content
Menu
This question has been flagged
2 Replies
11106 Views

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
0
Jul 18
1602
2
Aug 22
2162
1
Aug 22
1419
2
Dec 24
136
1
Nov 24
201