forvas
forvas

Reputation: 10189

Unable to translate a term inside a Qweb condition in Odoo 10. How to do this?

I'm trying to translate a specific term which appears in a Qweb report, but its behaviour is very different from expected.

If you install the standard sale module in Odoo 10, take a look at its sale order report (XML ID = report_saleorder_document). Its code is in the report folder, file sale_report_templates.xml. You'll find the following line:

<td><span t-esc="amount_by_group[0] or 'Taxes'"/></td>

As you can see, there is a literal string, Taxes, which must be translated if you choose a language different from English. Try to translate the word to a language which hasn't translated it yet.

In my case, I'm trying to translate the term to Galician, in which the translation of Taxes was empty:

#. module: sale
#: model:ir.model.fields,field_description:sale.field_sale_order_amount_tax
#: model:ir.model.fields,field_description:sale.field_sale_order_line_price_tax
#: model:ir.model.fields,field_description:sale.field_sale_order_line_tax_id
#: model:ir.ui.view,arch_db:sale.report_invoice_layouted
#: model:ir.ui.view,arch_db:sale.report_saleorder_document
msgid "Taxes"
msgstr "Impostos"

But after restarting the service, updating the sale module, loading the Galician translation overwriting terms, synchronizing the terms, updating the browser, removing its cookies, and even updating base module, nothing happened.

Then I made the following query in PostgreSQL:

SELECT id, lang, src, name, module, value, res_id FROM ir_translation WHERE src='Taxes' AND lang='gl_ES' ORDER BY id DESC;

   id   | lang  |  src  |               name                |  module  |    value    | res_id 
--------+-------+-------+-----------------------------------+----------+-------------+--------
 123634 | gl_ES | Taxes | account.account.tag,applicability | account  | Taxes       |      0
 121625 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Taxes       |    364
 121624 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Taxes       |    428
 121619 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Taxes       |    414
 121618 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Taxes       |    415
 121617 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Taxes       |    441
 120817 | gl_ES | Taxes | ir.ui.menu,name                   | account  | Taxes       |    108
 113387 | gl_ES | Taxes | ir.model.fields,field_description | account  | Taxes       |   2878
 113385 | gl_ES | Taxes | ir.model.fields,field_description | account  | Taxes       |   2700
 111845 | gl_ES | Taxes | ir.actions.act_window,name        | account  | Taxes       |    158
 111431 | gl_ES | Taxes | account.tax.group,name            | account  | Taxes       |      1
  47094 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Taxes       |    430
  46953 | gl_ES | Taxes | ir.ui.view,arch_db                | purchase | Impostos    |    746
  46952 | gl_ES | Taxes | ir.model.fields,field_description | purchase | Impostos    |   5045
  46951 | gl_ES | Taxes | ir.model.fields,field_description | purchase | Impostos    |   4992
  45544 | gl_ES | Taxes | ir.ui.view,arch_db                | sale     | Impostos    |    554
  45543 | gl_ES | Taxes | ir.ui.view,arch_db                | sale     | Impostos    |    556
  45542 | gl_ES | Taxes | ir.model.fields,field_description | sale     | Impostos    |   4128
  45541 | gl_ES | Taxes | ir.model.fields,field_description | sale     | Impostos    |   4120
  45540 | gl_ES | Taxes | ir.model.fields,field_description | sale     | Impostos    |   4085
(20 rows)

And I realized that the problem is that may be I had to translate the account module too (which I didn't understand because the term is in sale module), so I went to the Galician translation file of account module and updated it:

#. module: account
#: selection:account.account.tag,applicability:0
#: model:account.tax.group,name:account.tax_group_taxes
#: model:ir.actions.act_window,name:account.action_tax_form
#: model:ir.model.fields,field_description:account.field_account_invoice_line_invoice_line_tax_ids
#: model:ir.model.fields,field_description:account.field_account_move_line_tax_ids
#: model:ir.ui.menu,name:account.menu_action_tax_form
#: model:ir.ui.view,arch_db:account.account_planner
#: model:ir.ui.view,arch_db:account.invoice_form
#: model:ir.ui.view,arch_db:account.invoice_supplier_form
#: model:ir.ui.view,arch_db:account.report_invoice_document
#: model:ir.ui.view,arch_db:account.view_account_config_settings
#: model:ir.ui.view,arch_db:account.view_move_line_form
msgid "Taxes"
msgstr "Impostos"

But same problem, so I did the same query again and the result was this:

   id   | lang  |  src  |               name                |  module  |    value    | res_id 
--------+-------+-------+-----------------------------------+----------+-------------+--------
 123634 | gl_ES | Taxes | account.account.tag,applicability | account  | Impostos    |      0
 121625 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Impostos    |    364
 121624 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Impostos    |    428
 121619 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Impostos    |    414
 121618 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Impostos    |    415
 121617 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Impostos    |    441
 120817 | gl_ES | Taxes | ir.ui.menu,name                   | account  | Impostos    |    108
 113387 | gl_ES | Taxes | ir.model.fields,field_description | account  | Impostos    |   2878
 113385 | gl_ES | Taxes | ir.model.fields,field_description | account  | Impostos    |   2700
 111845 | gl_ES | Taxes | ir.actions.act_window,name        | account  | Impostos    |    158
 111431 | gl_ES | Taxes | account.tax.group,name            | account  | Taxes       |      1
  47094 | gl_ES | Taxes | ir.ui.view,arch_db                | account  | Impostos    |    430
  46953 | gl_ES | Taxes | ir.ui.view,arch_db                | purchase | Impostos    |    746
  46952 | gl_ES | Taxes | ir.model.fields,field_description | purchase | Impostos    |   5045
  46951 | gl_ES | Taxes | ir.model.fields,field_description | purchase | Impostos    |   4992
  45544 | gl_ES | Taxes | ir.ui.view,arch_db                | sale     | Impostos    |    554
  45543 | gl_ES | Taxes | ir.ui.view,arch_db                | sale     | Impostos    |    556
  45542 | gl_ES | Taxes | ir.model.fields,field_description | sale     | Impostos    |   4128
  45541 | gl_ES | Taxes | ir.model.fields,field_description | sale     | Impostos    |   4120
  45540 | gl_ES | Taxes | ir.model.fields,field_description | sale     | Impostos    |   4085
(20 rows)

So I thought that the problem was this translation:

111431 | gl_ES | Taxes | account.tax.group,name            | account  | Taxes

And it is. If I modify this translation through a query in PostgreSQL, then when I print the sale order report, I can see the word translated to Galician.

But my question is: what I have to do to translate that term through PO files and without executing a query?

It's annoying as in some languages like Spanish the term is well translated through PO files... I think that this problem is easy to replicate, so I'll appreciate a lot if anyone tries it, understands what is happening and can explain it to me.

Upvotes: 3

Views: 1850

Answers (1)

Travis Waelbroeck
Travis Waelbroeck

Reputation: 2135

I see the problem you've described and it does seem to be a bit surprising.

No matter what I tried, I was not able to get specifically that term updated by changing the gl.po file, nor by creating my own gl.po file. I was able to update other terms through that method, which suggests this might be a bug with that specific term for some reason.

Having said that, you can update the term manually through the user interface.

  1. Activate the Developer Mode
  2. Go to Settings > Translations > Application Terms > Translated Terms
  3. Search:
    • Source Term = Taxes
    • Translated Field = account.tax.group,name
  4. Update the Translation Value to Impostos (or whatever you prefer)

If you specifically need an automatic way to handle this and can't rely on a manual process, then you could modify the way that _get_tax_amount_by_group works.

@api.multi
def _get_tax_amount_by_group(self):
    ...
    from openerp.tools.translate import translate
    res = map(lambda l: (translate(self._cr, 'ir.ui.view,arch_db', 'model', self.partner_id.lang, l[0].name), l[1]), res)
    ...

Upvotes: 0

Related Questions