diff --git a/report_xlsx/report/report_abstract_xlsx.py b/report_xlsx/report/report_abstract_xlsx.py index af7ce658f..3e70aac48 100644 --- a/report_xlsx/report/report_abstract_xlsx.py +++ b/report_xlsx/report/report_abstract_xlsx.py @@ -91,6 +91,13 @@ class ReportXlsxAbstract(models.AbstractModel): ids = self.env.context.get("active_ids", []) 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). + 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}'}" + def create_xlsx_report(self, docids, data): objs = self._get_objs_for_report(docids, data) file_data = BytesIO() diff --git a/report_xlsx/tests/test_report.py b/report_xlsx/tests/test_report.py index da001f47f..a254294b1 100644 --- a/report_xlsx/tests/test_report.py +++ b/report_xlsx/tests/test_report.py @@ -15,7 +15,7 @@ except ImportError: class TestReport(common.TransactionCase): def setUp(self): - super(TestReport, self).setUp() + super().setUp() report_object = self.env["ir.actions.report"] self.xlsx_report = self.env["report.report_xlsx.abstract"].with_context( active_model="res.partner" @@ -55,3 +55,13 @@ class TestReport(common.TransactionCase): # Typical call from render objs = self.xlsx_report._get_objs_for_report(self.docs.ids, {}) self.assertEqual(objs, self.docs) + + 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 €" + )