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

I want that when you change the suplier in the Purchas Order, automatically change the description of the products in the order lines, meeting the code and the name of that supplier if it is specified in  the product. The problem is that this code changes everything to the first value. What can I do to go line by line checking the product name and not putting all time the same

@api.onchange('partner_id')
def _onchange_partner_id(self):
for order in self:
product_lang = self.product_id.with_context(
lang=self.partner_id.lang,
partner_id=self.partner_id.id,
)
self.name = product_lang.display_name
if product_lang.description_purchase:
self.name += '\n' + product_lang.description_purchase
for line in order.order_line:
line.name = self.name
Avatar
Discard

Hi bro, 

I edited my answer to match your odoo version V12, its right here :

https://www.odoo.com/fr_FR/forum/aide-1/question/change-products-when-supplier-is-changed-160405#answer-160425

Author Best Answer
@api.onchange('partner_id')
def _onchange_partner_id(self):
for line in self.order_line:
product_lang = line.product_id.with_context(
lang=self.partner_id.lang,
partner_id=self.partner_id.id, )
name = product_lang.display_name
if product_lang.description_purchase:
name += '\n' + product_lang.description_purchase
line.name = name

This is the solution, thank you all for your help!


Avatar
Discard

Hello Okatent;

may you please share where/how we should apply your solution. Thanks in advance.