Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions account_credit_control/models/credit_control_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<th style='%s'>%s</th>" % (th_style, _("Invoice number"))
tr_content += "<th style='%s'>%s</th>" % (th_style, _("Payment Reference"))
Expand Down
1 change: 1 addition & 0 deletions account_credit_control/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2026 360ERP (<https://www.360erp.com>)
# 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)
Loading