Se rendre au contenu
Menu
Cette question a été signalée
3 Réponses
3538 Vues

How to restrict vendor creation without affecting customer in odoo 17 ? from all he forms. 
Please advice, if i remove create access in res.partner object. Can't allowing to create customer  also. Without affecting customer part I want to restrict vendor creation. 


I want to restrict product creation by access rights or using studio, without touching the coding part

Avatar
Ignorer
Meilleure réponse

Hi,


You can restrict vendor creation without affecting customer creation in Odoo by following these steps:


1. Go to Settings and enable Developer Mode.

2. Create a new group in Settings > Users & Companies > Groups > New. Add all the users to whom you want to give create access, and select all the access rights for that group.

3. Create a new record rule in Settings > Technical > Record Rules under the Security section with the configuration below:

Domain filter: Ensure to include the group ID (116 in this example) that we created earlier.

4. Now, only the users in the newly created group can create a vendor.

5. After these configurations, non-access members may still be able to create a vendor (who are typically not vendors) as a contact in the Product template purchase tab. To prevent this, restrict the "Create" and "Create/Edit" permissions for all users using the Studio application.


Click Studio icon from the product template page and click on purchase tab and select Edit list view.


After that click "Vendor" on the list view and check the highlighted checkboxes on the left side of the screen and save the changes.



Hope this helps.


Thanks.

Avatar
Ignorer
Auteur

When I try to save this record rule getting this warning "Invalid domain: not enough values to unpack (expected 3, got 1)"

['I', ('supplier_rank', '=',0), ('create_uid.groups_id', 'in', [226])]

In the domain filter, you wrongly placed 'I' instead of '|'. That's why the warning is raised. Replace it with ['|', ('supplier_rank', '=', 0), ('create_uid.groups_id', 'in', [226])] and it will work fine.

Auteur

Yes, it is works fine to restrict vendor creation. Can I restrict product creation by this way?

Auteur Meilleure réponse

Without touching the coding part I want to restrict. From the front end edit form view or studio or using access rights group.

Avatar
Ignorer

Replace the domain filter with ['|', ('supplier_rank', '=',0), ('create_uid.groups_id', 'in', [226])]

Meilleure réponse

Hello dhivya.n@galileosolutionpartners.com,


To restrict the creation of vendors in Odoo 17 while allowing customers to be created, follow these refined steps to implement a comprehensive solution:



1. if you want to remove create access for specific vendor view for same res.partner obj ,you can manage by this in res.partner you can use get_view method.

//Code1 in Comment//

by this contact creation is not restricted, only vendor creation is restricted as you can see below images




2. if you want to raise error at time of vendor creation add below code of snippet in res_partner.py file.

//Code2 in Comment//

3. To restrict vendor creation totally, you have to remove create access from the product template's puchase tab and in purchase order , so for that add below snippet code in xml file.


//Code3 in Comment//


by using this you can restrict vendor creation by considering multiple scenario as I have Provided.


Hope this Helps,


If you need any help in customization feel free to contact us..


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Avatar
Ignorer

Code 1:

@api.model
def get_views(self, views, options=None):
res = super().get_views(views=views, options=options)
action_id = self.env["ir.actions.act_window"].browse(options.get("action_id"))
context = ast.literal_eval(action_id.context)
context.update({'create': False})
action_id.context = context
return res

Code 2 :

@api.model
def create(self, vals):
res = super().create(vals)
if self.env.context.get("res_partner_search_mode") == 'supplier':
raise UserError("You can't create vendor !!")
return res

Code 3:

<record id="product_supplierinfo_subcontractor_tree_view_test" model="ir.ui.view">
<field name="name">product.supplierinfo.subcontractor.tree.view.test</field>
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="options">{'no_create': True, 'no_open': True}</attribute>
</xpath>
</field>
</record>

<record id="view_purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="options">{'no_create': True, 'no_open': True}</attribute>
</field>
</field>
</record>

Publications associées Réponses Vues Activité
0
août 23
8
2
nov. 22
3073
2
mars 15
4363
1
mars 22
3076
0
sept. 19
1890