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

In previous versions we had the ir.translation model to manage the translations.

Now in version 16.0, how can I update all my product's name using python, to have all translations (en_US, pt_BR, ...) being the same?

for example, the current situation:

{"en_US": "Table (copy)", "pt_BR": "Chair"}

and the desired situation:

{"en_US": "Chair", "pt_BR": "Chair"}

thanks

形象
丢弃
最佳答案

Hello Guilherme !

Thank you for your question ! With the Odoo shell, you can use the following to write (or read) that product in the language of your choice

product_id = 1990904  # Your product_id goes here
product = env["product.template"].browse(product_id)
product.with_context({"lang": "en_US"}).name = "Chair"

(Don't forget to commit your changes with env.cr.commit() once you want to save your changes)

You can then double check if the change is correct by using 

product.with_context({"lang": "en_US"}).name

Which will return you "Chair"


Hope this helps ! :)


EDIT (thanks Ray), you can also search for your product as such

product = env["product.template"].search([("name", "=", "Table (copy)")])

in case you are unsure of its id, since product.product ids are different than product.template ids

形象
丢弃

Anyone doing this, please don't mix up the product.product with the product.template.

Things you see on Sales Orders, Invoices, Warehouse Transfers are "product.product" records so their ID would not be used to find the corresponding product.template.

相关帖文 回复 查看 活动
Odoo 16 已解决
1
12月 22
3657
8
1月 25
5825
3
3月 24
2290
1
7月 23
1710
2
5月 23
4428