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.

55 lines
1.9 KiB

  1. # Copyright 2017 Creu Blanca
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. import logging
  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 = (
  15. self.env['report.report_xlsx.abstract']
  16. .with_context(active_model='res.partner')
  17. )
  18. self.report_name = 'report_xlsx.partner_xlsx'
  19. self.report = report_object._get_report_from_name(self.report_name)
  20. self.docs = self.env['res.company'].search([], limit=1).partner_id
  21. def test_report(self):
  22. report = self.report
  23. self.assertEqual(report.report_type, 'xlsx')
  24. rep = report.render(self.docs.ids, {})
  25. wb = open_workbook(file_contents=rep[0])
  26. sheet = wb.sheet_by_index(0)
  27. self.assertEqual(sheet.cell(0, 0).value, self.docs.name)
  28. def test_id_retrieval(self):
  29. # Typical call from WebUI with wizard
  30. objs = self.xlsx_report._get_objs_for_report(
  31. False, {"context": {"active_ids": self.docs.ids}})
  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)._get_objs_for_report(False, False)
  36. self.assertEquals(objs, self.docs)
  37. # Typical call from WebUI
  38. objs = self.xlsx_report._get_objs_for_report(
  39. self.docs.ids,
  40. {"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)