Search code examples
pythonodootranslationodoo-13po

Export Python variable translations not working


I'm developing a custom module in Odoo 13 to generate a personalized XMLS report, and for this I'm using Base Report XLSX from OCA. The issue is that when generating the PO document for the translations, it doesn't recognize the variables that I explicitly marked to export whit "_()", even though I followed all the indications in the official documentation (I think).

The custom module code:

# -*- coding: utf-8 -*-
from odoo import models, _
class PayrollBatchReportXLSX(models.AbstractModel):
    _name = 'report.company_payroll.payroll_batch_report'
    _inherit = 'report.report_xlsx.abstract'
    def generate_xlsx_report(self, workbook, data, lines):
        sheet = workbook.add_worksheet('Payroll Batch XLSX Report')
        sheet.write(0, 0, _("ACCOUNT"))
        sheet.write(0, 1, _("DEBIT"))
        sheet.write(0, 2, _("CREDIT"))
        sheet.write(0, 3, _("NAME"))
        line_index = 0
        for line_item in lines.slip_ids.line_ids:
            if line_item.salary_rule_id.category_id.code in ['L10N_HN_NET']:
                sheet.write(line_index+1, 2, line_item.total)
                line_index += 1
        for index, employee in enumerate(lines.slip_ids.employee_id):
            sheet.write(index+1, 3, employee.name.upper())
            if employee.bank_account_id.acc_number:
                sheet.write(index+1, 0, employee.bank_account_id.acc_number)

And this is the generated PO file:

# Translation of Odoo Server.
# This file contains the translation of the following modules:
#  * company_payroll
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-05-04 16:17+0000\n"
"PO-Revision-Date: 2022-05-04 16:17+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: company_payroll
#: model:ir.actions.report,print_report_name:company_payroll.payroll_batch_xlsx_report
msgid "'Payroll batch - %s' % (object.name)"
msgstr "'Nómina en lote - %s' % (object.name)"
#. module: company_payroll
#: model:ir.model.fields,field_description:company_payroll.field_report_company_payroll_payroll_batch_report__display_name
msgid "Display Name"
msgstr "Mostrar nombre"
#. module: company_payroll
#: model:ir.model.fields,field_description:company_payroll.field_report_company_payroll_payroll_batch_report__id
msgid "ID"
msgstr ""
#. module: company_payroll
#: model:ir.model.fields,field_description:company_payroll.field_report_company_payroll_payroll_batch_report____last_update
msgid "Last Modified on"
msgstr "Última modificación en"
#. module: company_payroll
#: model:ir.actions.report,name:company_payroll.payroll_batch_xlsx_report
msgid "Payroll Batch XLSX Report"
msgstr "Reporte de nómina por lote"
#. module: company_payroll
#: model:ir.model,name:company_payroll.model_report_company_payroll_payroll_batch_report
msgid "report.company_payroll.payroll_batch_report"
msgstr ""

As you can see, the variables to be translated ("_("ACCOUNT")", "_("DEBIT")", etc.) aren't shown anywhere. I hope you can help me, thanks in advance.


Solution

  • Two months later I finally found the answer, happens that Odoo wasn't pulling translations because the name of my module was separated by hyphens (-), and this, for some reason, made Odoo not recognize my fields to translate. Simply replace hyphens dashes with underscores (_).

    Thanks to the person who answered me in the comments (seems that those were deleted).