跳至内容
菜单
此问题已终结
2 回复
1917 查看

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
形象
丢弃

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

编写者 最佳答案
@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!


形象
丢弃

Hello Okatent;

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