From abefc21679ae10954ffee00b97403677911eb8f2 Mon Sep 17 00:00:00 2001 From: Tarek Lokal Date: Sat, 11 Jul 2026 16:16:50 +0200 Subject: [PATCH] fix(spp_programs): honor user locale in total_amount_in_words (#236) Derive num2words language from env context or user lang instead of hardcoding English; fall back to en for unsupported locales. Co-authored-by: Cursor --- spp_programs/models/cycle.py | 6 +++++- spp_programs/tests/test_cycle.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spp_programs/models/cycle.py b/spp_programs/models/cycle.py index 21b0b2df..c2c30d1e 100644 --- a/spp_programs/models/cycle.py +++ b/spp_programs/models/cycle.py @@ -260,7 +260,11 @@ def _compute_total_amount(self): def _compute_total_amount_in_words(self): for record in self: if record.total_amount and record.currency_id: - amount_in_words = num2words(record.total_amount, lang="en").title() + lang_code = (self.env.context.get("lang") or self.env.user.lang or "en_US").split("_")[0] + try: + amount_in_words = num2words(record.total_amount, lang=lang_code).title() + except NotImplementedError: + amount_in_words = num2words(record.total_amount, lang="en").title() record.total_amount_in_words = f"{amount_in_words} {record.currency_id.name}" else: record.total_amount_in_words = "" diff --git a/spp_programs/tests/test_cycle.py b/spp_programs/tests/test_cycle.py index 005247ac..da065c7f 100644 --- a/spp_programs/tests/test_cycle.py +++ b/spp_programs/tests/test_cycle.py @@ -433,6 +433,10 @@ def test_total_amount_in_words(self, mock_today): cycle._compute_total_amount_in_words() self.assertIn("Five Hundred", cycle.total_amount_in_words) + cycle_fr = cycle.with_context(lang="fr_FR") + cycle_fr._compute_total_amount_in_words() + self.assertIn("cinq cents", cycle_fr.total_amount_in_words.lower()) + def test_approval_state_mapping(self): """_compute_approval_state maps cycle state to the approval mixin state correctly.""" cycle = self._make_cycle(name="Approval State Mapping Cycle [CYCLE TEST]")