[IMP] report_xlsx: Method for getting cell format for a currency
TT38722pull/647/head
parent
8dffdf6a27
commit
36de5e376c
|
@ -91,6 +91,13 @@ class ReportXlsxAbstract(models.AbstractModel):
|
||||||
ids = self.env.context.get("active_ids", [])
|
ids = self.env.context.get("active_ids", [])
|
||||||
return self.env[self.env.context.get("active_model")].browse(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):
|
def create_xlsx_report(self, docids, data):
|
||||||
objs = self._get_objs_for_report(docids, data)
|
objs = self._get_objs_for_report(docids, data)
|
||||||
file_data = BytesIO()
|
file_data = BytesIO()
|
||||||
|
|
|
@ -15,7 +15,7 @@ except ImportError:
|
||||||
|
|
||||||
class TestReport(common.TransactionCase):
|
class TestReport(common.TransactionCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestReport, self).setUp()
|
super().setUp()
|
||||||
report_object = self.env["ir.actions.report"]
|
report_object = self.env["ir.actions.report"]
|
||||||
self.xlsx_report = self.env["report.report_xlsx.abstract"].with_context(
|
self.xlsx_report = self.env["report.report_xlsx.abstract"].with_context(
|
||||||
active_model="res.partner"
|
active_model="res.partner"
|
||||||
|
@ -55,3 +55,13 @@ class TestReport(common.TransactionCase):
|
||||||
# Typical call from render
|
# Typical call from render
|
||||||
objs = self.xlsx_report._get_objs_for_report(self.docs.ids, {})
|
objs = self.xlsx_report._get_objs_for_report(self.docs.ids, {})
|
||||||
self.assertEquals(objs, self.docs)
|
self.assertEquals(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 €"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue