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.

60 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2009-2017 Noviat.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. class TestCommonXls(TransactionCase):
  6. """ Common tests for all XLS Exports """
  7. def setUp(self):
  8. super(TestCommonXls, self).setUp()
  9. self.model = self.env[self._getReportModel()]
  10. self.xls_report_name = self._getXlsReportName()
  11. ctx = {'xls_export': 1}
  12. self.xls_action_name = self._getXlsReportActionName()
  13. self.xls_action = self.env.ref(self.xls_action_name).with_context(ctx)
  14. wiz_vals = {'chart_account_id': self.env.ref('account.chart0').id}
  15. wiz_vals.update(self._getBaseFilters())
  16. self.report = self.model.with_context(ctx).create(wiz_vals)
  17. def common_test_01_action_xls(self):
  18. """ Check if report XLS action is correct """
  19. report_action = self.report.xls_export()
  20. self.assertDictContainsSubset(
  21. {'type': 'ir.actions.report.xml',
  22. 'report_name': self.xls_report_name},
  23. report_action)
  24. self.render_dict = report_action['datas']
  25. def common_test_02_render_xls(self):
  26. report_xls = self.xls_action.render_report(
  27. self.report.ids,
  28. self.xls_report_name,
  29. self.render_dict)
  30. self.assertGreaterEqual(len(report_xls[0]), 1)
  31. self.assertEqual(report_xls[1], 'xls')
  32. def _getReportModel(self):
  33. """
  34. :return: the report model name
  35. """
  36. raise NotImplementedError()
  37. def _getXlsReportName(self):
  38. """
  39. :return: the xls report name
  40. """
  41. raise NotImplementedError()
  42. def _getXlsReportActionName(self):
  43. """
  44. :return: the xls report action name
  45. """
  46. raise NotImplementedError()
  47. def _getBaseFilters(self):
  48. """
  49. :return: the minimum required filters to generate report
  50. """
  51. raise NotImplementedError()