Skip to content

Commit

Permalink
report_xlsx: Fix currency format
Browse files Browse the repository at this point in the history
  • Loading branch information
mmequignon committed Dec 19, 2024
1 parent e88d22e commit df36b6e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 2 additions & 4 deletions report_xlsx/report/report_abstract_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ def _get_objs_for_report(self, docids, data):
return self.env[self.env.context.get("active_model")].browse(ids)

def _report_xlsx_currency_format(self, currency):
"""Get the format to be used in cells (symbol included).
"""Get currency format to be used in cells.
Used in account_financial_report addon"""
s_before = currency.symbol if currency.position == "before" else ""
s_after = " %s" % currency.symbol if currency.position == "after" else ""
return f"{f'{s_before}'}#,##0.{'0' * currency.decimal_places}{f'{s_after}'}"
return f"#,##0.{'0' * currency.decimal_places}"

def create_xlsx_report(self, docids, data):
objs = self._get_objs_for_report(docids, data)
Expand Down
6 changes: 1 addition & 5 deletions report_xlsx/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,5 @@ def test_id_retrieval(self):
def test_currency_format(self):
usd = self.env.ref("base.USD")
self.assertEqual(
self.xlsx_report._report_xlsx_currency_format(usd), "$#,##0.00"
)
eur = self.env.ref("base.EUR")
self.assertEqual(
self.xlsx_report._report_xlsx_currency_format(eur), "#,##0.00 €"
self.xlsx_report._report_xlsx_currency_format(usd), "#,##0.00"
)

0 comments on commit df36b6e

Please sign in to comment.