forvas
forvas

Reputation: 10189

How to import a field value translation in Odoo 11 by CSV?

I am importing product templates through a CSV file. One of the columns of the file is description_sale, which is in English. But I was also given the description_sale column in other languages, to import its translations to see the right words when doing actions like printing a sale order PDF report for a customer. In this case the descrition_sale field should be shown in the customer's language.

To manage that, I need to import the translations of the column. I have tried creating a new CSV file to import in the ir_translation table. I was able to fill in every column except for the res_id one. The problem is that is not a Many2one field, but an Integer. So I cannot put res_id/id at the column header and fill the column in with the XML IDs of the product templates I am importing.

Can I perform this operation in a simple way? I am thinking about using the shell and other complex things I hope there are no necessary to do such a common task.

Upvotes: 1

Views: 702

Answers (1)

SlyK
SlyK

Reputation: 185

If I get it right, you have a CSV which has two (or more) columns which should be put into description_sale field: the first one is the product description in English, while the other columns refer to the same field in some other language.

The easiest way to import those translations, is to do it while importing the whole CSV itself, without creating another CSV. Let's say we have 3 CSV columns: Sale Descr EN, Sale Descr DE, Sale Descr FR. All you have to do is to create your product first, then update it like this:

DESCR_LANG_MAP = {
    'de_DE': 'Sale Descr DE',
    'en_US': 'Sale Descr EN',
    'fr_FR': 'Sale Descr FR',
}

prod_tmpl = self.env['product.template'].create(vals)

for lang, col_name in DESCR_LANG_MAP.items():
    prod_tmpl.with_context(lang=lang).write({
        'description_sale': csvrow.get(col_name, '')
    })

Upvotes: 1

Related Questions