Skip to content

Commit 5c962ba

Browse files
committed
fix(spp_programs): use format_amount for thousands separator on entitlement summary (#941 r3)
QA round-3 follow-up: amounts on the 'What Do They Receive?' overview were rendered with currency symbol + 2-decimal precision but without thousands grouping (e.g. "$ 1000000.00" instead of "$ 1,000,000.00"). Switch both render paths in program_manager_ui.py to odoo.tools.misc. format_amount, which gives locale-aware grouping plus correct currency symbol position out of the box: - _manager_detail_entitlement_items - _manager_detail_basic_cash Adds test_items_summary_includes_thousands_separator covering the 1,000,000 case. Local run: 0 failed of 3 tests.
1 parent aee395d commit 5c962ba

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

spp_programs/models/program_manager_ui.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from odoo import _, api, fields, models
10+
from odoo.tools.misc import format_amount
1011

1112

1213
def _format_recurrence(duration, rrule_type):
@@ -487,11 +488,7 @@ def _manager_detail_entitlement_items(self, concrete):
487488
multiplier_field = getattr(item, "multiplier_field", False)
488489
condition = getattr(item, "condition", "") or ""
489490
currency = getattr(item, "currency_id", False)
490-
currency_sym = (currency.symbol or currency.name) if currency else ""
491-
precision = currency.decimal_places if currency else 2
492-
amount_with_sym = (
493-
f"{currency_sym} {amount:.{precision}f}".strip() if currency_sym else f"{amount:.{precision}f}"
494-
)
491+
amount_with_sym = format_amount(self.env, amount, currency) if currency else f"{amount:,.2f}"
495492
if amount_expr:
496493
line = _("Amount per beneficiary: %s") % amount_expr
497494
elif multiplier_field:
@@ -517,27 +514,22 @@ def _manager_detail_basic_cash(self, concrete):
517514
fee_pct = getattr(concrete, "transfer_fee_pct", 0) or 0
518515
fee_amount = getattr(concrete, "transfer_fee_amount", 0) or 0
519516
currency = getattr(concrete, "currency_id", False)
520-
currency_sym = (currency.symbol or currency.name) if currency else ""
521-
precision = currency.decimal_places if currency else 2
522517

523518
def _fmt(amt):
524-
return f"{amt:.{precision}f}"
519+
return format_amount(self.env, amt, currency) if currency else f"{amt:,.2f}"
525520

526521
lines = []
527522
if per_cycle:
528-
lines.append(_("Amount per cycle: %(sym)s %(amt)s") % {"sym": currency_sym, "amt": _fmt(per_cycle)})
523+
lines.append(_("Amount per cycle: %s") % _fmt(per_cycle))
529524
if per_person:
530-
line = _("Amount per person in group: %(sym)s %(amt)s") % {
531-
"sym": currency_sym,
532-
"amt": _fmt(per_person),
533-
}
525+
line = _("Amount per person in group: %s") % _fmt(per_person)
534526
if max_people:
535527
line += _(" (up to %s people)") % max_people
536528
lines.append(line)
537529
if fee_pct:
538530
lines.append(_("Transfer fee: %s%% of amount") % fee_pct)
539531
elif fee_amount:
540-
lines.append(_("Transfer fee: %(sym)s %(amt)s flat") % {"sym": currency_sym, "amt": _fmt(fee_amount)})
532+
lines.append(_("Transfer fee: %s flat") % _fmt(fee_amount))
541533
if not lines:
542534
return _("No amount configured yet — click Edit above to set how much each beneficiary receives per cycle.")
543535
return "\n".join(lines)

spp_programs/tests/test_manager_summary_formatting.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,26 @@ def test_basic_cash_summary_two_decimals(self):
8888
currency = self.program.journal_id.currency_id
8989
sym = currency.symbol or currency.name
9090
self.assertIn(sym, summary)
91+
92+
def test_items_summary_includes_thousands_separator(self):
93+
"""Round-3 QA: large amounts must group thousands (1,000,000.00 not 1000000.00)."""
94+
cash = self.env["spp.program.entitlement.manager.cash"].create(
95+
{
96+
"name": "Cash Large Amount [TEST]",
97+
"program_id": self.program.id,
98+
"approval_definition_id": self.approval_def.id,
99+
}
100+
)
101+
self.env["spp.program.entitlement.manager.cash.item"].create(
102+
{
103+
"entitlement_id": cash.id,
104+
"amount": 1_000_000.0,
105+
}
106+
)
107+
self._wrap_manager(cash)
108+
109+
summary = self.program.entitlement_manager_detail or ""
110+
# Should include a comma in the grouped amount for en_US locale.
111+
self.assertIn("1,000,000", summary, f"summary missing thousands separator: {summary!r}")
112+
# And of course still no bare "1000000" without a separator.
113+
self.assertNotRegex(summary, r"\b1000000\b")

0 commit comments

Comments
 (0)