Skip to Content
Menu
This question has been flagged

I have added Vendor dropdown using custom field on Sale Order Line form, now there dispay all vendors but actually want to display product wise Vendors in dropdown


For Example

Product 1

    - Vendor1

    - Vendor2

    - Vendor3


Product 2

    - Vendor4

    - Vendor5


So when we place order for product1 then show only Vendor 1,2 and 3 not all all 5 vendors, currently showing all 5 vendors,


can anyone help me regarding this how can we filter vendor product wise when we place new order.


Thanks a lot

Avatar
Discard

you can use domain filtering on your many2one field or drop down field: http://learnopenerp.blogspot.com/2016/10/onchange-many2one-filed-in-odoo.html

Author

Hello Everyone,

Thanks for your answers but can i know how can i add this code in custom field, I have followed below steps,

1) Added custom field x_vendors_id on sale order line using Settings -> Database Structure -> Models

2) Added below code in EditView on Sale Order for page.

<label for="x_vendors_id" string="Choose Vendor"/>

<div>

<field name="x_vendors_id" context="{'search_default_supplier':1, 'default_supplier':1, 'default_customer':0}" domain="[('supplier','=',True)]"/>

</div>

3) added custom code (your answers) on 1st step custom field page in "compute" field but not working.

can you please let me know it right way or do i need add it on another way?

Again Thank you much all of you.

NIKHIL KRISHNAN

api.onchange('product_id')

def onchange_project(self):

partner_ids = []

if self.product_id:

partner_ids = self.product_id.sellers_ids

return {'domain': {'tag_ids': [('id', 'in', partner_ids)]}}

Sudhir Aarya

@api.onchange('product_id')

def onchange_product(self):

if self.product_id:

return {'domain': {'x_vendors_id': [('id', 'in', [seller.name.id for seller in self.product_id.seller_ids])]}}`

Best Answer

You can return a vendor domain from product onchange method.

Try following code:

@api.onchange('product_id')
def onchange_product(self):
if self.product_id:
    return {'domain': {'your_partner_id_field': [('id', 'in', [seller.name.id for seller in self.product_id.seller_ids])]}}

See related question Project Tags Domain

Avatar
Discard
Best Answer

Hi Kunjal Popat,
Just try this code.

api.onchange('product_id')
def onchange_project(self):
partner_ids = []
if self.product_id:
partner_ids = self.product_id.sellers_ids
return {'domain': {'tag_ids': [('id', 'in', partner_ids)]}}

Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 22
1521
2
Mar 18
2776
0
Jan 23
683
0
Dec 21
859
1
Sep 21
4618