diff --git a/account_credit_control/models/credit_control_communication.py b/account_credit_control/models/credit_control_communication.py index 55d2c6a71..8c2eb44af 100644 --- a/account_credit_control/models/credit_control_communication.py +++ b/account_credit_control/models/credit_control_communication.py @@ -176,6 +176,10 @@ def _generate_comm_from_credit_lines(self, lines): return comms def _get_credit_control_communication_table(self): + # Force context to contact's language before rendering strings + lang = self.contact_address_id.lang or "en_US" + self = self.with_context(lang=lang) + th_style = "padding: 5px; border: 1px solid black;" tr_content = "%s" % (th_style, _("Invoice number")) tr_content += "%s" % (th_style, _("Payment Reference")) diff --git a/account_credit_control/tests/__init__.py b/account_credit_control/tests/__init__.py index 72cadcddd..0aa55831f 100644 --- a/account_credit_control/tests/__init__.py +++ b/account_credit_control/tests/__init__.py @@ -3,3 +3,4 @@ from . import test_res_partner from . import test_account_move from . import test_credit_control_run +from . import test_credit_control_communication_translation diff --git a/account_credit_control/tests/test_credit_control_communication_translation.py b/account_credit_control/tests/test_credit_control_communication_translation.py new file mode 100644 index 000000000..bff091085 --- /dev/null +++ b/account_credit_control/tests/test_credit_control_communication_translation.py @@ -0,0 +1,66 @@ +# Copyright 2026 360ERP () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import tagged +from odoo.tests.common import TransactionCase + +from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + + +@tagged("post_install", "-at_install") +class TestCreditControlCommunicationTranslation(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + + # Activate Dutch language + cls.env["res.lang"]._activate_lang("nl_NL") + + # Create partner with Dutch language set + cls.partner_nl = cls.env["res.partner"].create( + { + "name": "Dutch Test Partner", + "lang": "nl_NL", + } + ) + + # Setup policy and communication record + cls.policy = cls.env.ref("account_credit_control.credit_control_3_time") + cls.policy_level = cls.env.ref("account_credit_control.3_time_1") + cls.policy_level.mail_show_invoice_detail = True + + cls.communication = cls.env["credit.control.communication"].create( + { + "partner_id": cls.partner_nl.id, + "contact_address_id": cls.partner_nl.id, + "policy_level_id": cls.policy_level.id, + "currency_id": cls.env.company.currency_id.id, + "company_id": cls.env.company.id, + } + ) + + def test_communication_table_language_propagation(self): + """Verify _get_credit_control_communication_table uses partner's lang.""" + # Generate table + table_html = self.communication._get_credit_control_communication_table() + + # Check headers that are reliably translated in the standard nl_NL locale + self.assertIn( + "Factuurnummer", + table_html, + "The context switch failed: 'Invoice number' was not translated.", + ) + self.assertIn( + "Vervaldatum", + table_html, + "The context switch failed: 'Due date' was not translated.", + ) + + def test_communication_table_fallback_lang(self): + """Verify table falls back gracefully when contact has no lang set.""" + self.partner_nl.lang = False + table_html = self.communication._get_credit_control_communication_table() + + # Fallback to source English strings + self.assertIn("Invoices summary", table_html)