OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB

  1. # Copyright 2017 Creu Blanca
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. import logging
  4. from odoo.tests import common
  5. _logger = logging.getLogger(__name__)
  6. try:
  7. from xlrd import open_workbook
  8. except ImportError:
  9. _logger.debug("Can not import xlrd`.")
  10. class TestReport(common.TransactionCase):
  11. def setUp(self):
  12. super(TestReport, self).setUp()
  13. report_object = self.env["ir.actions.report"]
  14. self.xlsx_report = self.env["report.report_xlsx.abstract"].with_context(
  15. active_model="res.partner"
  16. )
  17. self.report_name = "report_xlsx.partner_xlsx"
  18. self.report = report_object._get_report_from_name(self.report_name)
  19. self.docs = self.env["res.company"].search([], limit=1).partner_id
  20. def test_report(self):
  21. report = self.report
  22. self.assertEqual(report.report_type, "xlsx")
  23. rep = report.render(self.docs.ids, {})
  24. wb = open_workbook(file_contents=rep[0])
  25. sheet = wb.sheet_by_index(0)
  26. self.assertEqual(sheet.cell(0, 0).value, self.docs.name)
  27. def test_id_retrieval(self):
  28. # Typical call from WebUI with wizard
  29. objs = self.xlsx_report._get_objs_for_report(
  30. False, {"context": {"active_ids": self.docs.ids}}
  31. )
  32. self.assertEquals(objs, self.docs)
  33. # Typical call from within code not to report_action
  34. objs = self.xlsx_report.with_context(
  35. active_ids=self.docs.ids
  36. )._get_objs_for_report(False, False)
  37. self.assertEquals(objs, self.docs)
  38. # Typical call from WebUI
  39. objs = self.xlsx_report._get_objs_for_report(
  40. self.docs.ids, {"data": [self.report_name, self.report.report_type]}
  41. )
  42. self.assertEquals(objs, self.docs)
  43. # Typical call from render
  44. objs = self.xlsx_report._get_objs_for_report(self.docs.ids, {})
  45. self.assertEquals(objs, self.docs)