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]")