Skip to content

Commit f5569b1

Browse files
committed
fix(spp_programs): force currency symbol on the LEFT of amount on entitlement summary (#941 r3 followup)
QA flagged that the previous round-3 fix (which used odoo.tools.misc. format_amount) rendered the currency symbol on the RIGHT for currency records configured with position='after'. The program overview should always show the symbol on the LEFT for consistency. Replace format_amount with a small static helper _format_money that: - groups thousands with Python's :, formatter, - pads to currency.decimal_places (default 2), - always prefixes the symbol on the left, regardless of currency.position. Adds test_items_summary_symbol_appears_left_of_amount which explicitly sets currency.position='after' before asserting the rendered summary still puts the symbol left of the amount.
1 parent 5c962ba commit f5569b1

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

spp_programs/models/program_manager_ui.py

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

99
from odoo import _, api, fields, models
10-
from odoo.tools.misc import format_amount
1110

1211

1312
def _format_recurrence(duration, rrule_type):
@@ -479,6 +478,22 @@ def _manager_detail_cel(self, concrete):
479478
% target_label
480479
)
481480

481+
@staticmethod
482+
def _format_money(amount, currency):
483+
"""Render a Float amount with thousands grouping + 2-decimal precision,
484+
prefixed by the currency symbol on the left. We don't use
485+
odoo.tools.misc.format_amount here because it honours the currency's
486+
`position` field — which puts the symbol after the amount for some
487+
currency records — and the program overview should always show the
488+
symbol on the left for consistency.
489+
"""
490+
precision = currency.decimal_places if currency else 2
491+
formatted = f"{amount:,.{precision}f}"
492+
if not currency:
493+
return formatted
494+
symbol = currency.symbol or currency.name or ""
495+
return f"{symbol} {formatted}".strip()
496+
482497
def _manager_detail_entitlement_items(self, concrete):
483498
"""Render each entitlement_item line readably."""
484499
lines = []
@@ -488,7 +503,7 @@ def _manager_detail_entitlement_items(self, concrete):
488503
multiplier_field = getattr(item, "multiplier_field", False)
489504
condition = getattr(item, "condition", "") or ""
490505
currency = getattr(item, "currency_id", False)
491-
amount_with_sym = format_amount(self.env, amount, currency) if currency else f"{amount:,.2f}"
506+
amount_with_sym = self._format_money(amount, currency)
492507
if amount_expr:
493508
line = _("Amount per beneficiary: %s") % amount_expr
494509
elif multiplier_field:
@@ -516,7 +531,7 @@ def _manager_detail_basic_cash(self, concrete):
516531
currency = getattr(concrete, "currency_id", False)
517532

518533
def _fmt(amt):
519-
return format_amount(self.env, amt, currency) if currency else f"{amt:,.2f}"
534+
return self._format_money(amt, currency)
520535

521536
lines = []
522537
if per_cycle:

spp_programs/tests/test_manager_summary_formatting.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,33 @@ def test_items_summary_includes_thousands_separator(self):
111111
self.assertIn("1,000,000", summary, f"summary missing thousands separator: {summary!r}")
112112
# And of course still no bare "1000000" without a separator.
113113
self.assertNotRegex(summary, r"\b1000000\b")
114+
115+
def test_items_summary_symbol_appears_left_of_amount(self):
116+
"""QA round-4: currency symbol must render on the LEFT of the amount."""
117+
cash = self.env["spp.program.entitlement.manager.cash"].create(
118+
{
119+
"name": "Cash Symbol Position [TEST]",
120+
"program_id": self.program.id,
121+
"approval_definition_id": self.approval_def.id,
122+
}
123+
)
124+
self.env["spp.program.entitlement.manager.cash.item"].create(
125+
{
126+
"entitlement_id": cash.id,
127+
"amount": 500.0,
128+
}
129+
)
130+
# Force currency.position to 'after' to ensure our render still puts
131+
# the symbol on the left regardless of the currency record setting.
132+
self.program.journal_id.currency_id.position = "after"
133+
self._wrap_manager(cash)
134+
135+
summary = self.program.entitlement_manager_detail or ""
136+
currency = self.program.journal_id.currency_id
137+
sym = currency.symbol or currency.name
138+
# The symbol must appear before the amount substring in the summary.
139+
idx_sym = summary.find(sym)
140+
idx_amt = summary.find("500.00")
141+
self.assertNotEqual(idx_sym, -1, f"symbol missing from summary: {summary!r}")
142+
self.assertNotEqual(idx_amt, -1, f"amount missing from summary: {summary!r}")
143+
self.assertLess(idx_sym, idx_amt, f"symbol should be LEFT of amount, got: {summary!r}")

0 commit comments

Comments
 (0)