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.

102 lines
3.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. import odoo.tests.common as common
  5. from odoo.exceptions import ValidationError
  6. from cStringIO import StringIO
  7. from odoo.addons.report_xlsx.report.report_xlsx import ReportXlsx
  8. class PartnerXlsx(ReportXlsx):
  9. def generate_xlsx_report(self, workbook, data, partners):
  10. sheet = workbook.add_worksheet('sheet')
  11. sheet.write(0, 0, 'test')
  12. class TestHeaderFooter(common.TransactionCase):
  13. @classmethod
  14. def setUpClass(cls):
  15. super(TestHeaderFooter, cls).setUpClass()
  16. cls.report = PartnerXlsx('report.res.partner.xlsx',
  17. 'res.partner')
  18. def setUp(self):
  19. super(TestHeaderFooter, self).setUp()
  20. # Create Header
  21. self.header_001 = self.env['report.xlsx.hf'].create({
  22. 'name': 'Header 001',
  23. 'hf_type': 'header',
  24. 'value': '&LPage &P of &N &CFilename: &F &RSheetname: &A',
  25. })
  26. # Create Footer
  27. self.footer_001 = self.env['report.xlsx.hf'].create({
  28. 'name': 'Footer 001',
  29. 'hf_type': 'footer',
  30. 'value': '&LCurrent date: &D &RCurrent time: &T',
  31. })
  32. # Create Report
  33. self.report_xlsx = self.env['ir.actions.report.xml'].create({
  34. 'report_name': 'res.partner.xlsx',
  35. 'name': 'XLSX report',
  36. 'report_type': 'xlsx',
  37. 'model': 'res.partner',
  38. 'header_id': self.header_001.id,
  39. 'footer_id': self.footer_001.id,
  40. })
  41. def test_header_footer(self):
  42. """
  43. Check that the header and footer have been added to the worksheets
  44. """
  45. file_data = StringIO()
  46. partner = self.env['res.partner'].browse([1])
  47. workbook = self.report.create_workbook(
  48. file_data, {}, partner, self.report_xlsx)
  49. header = u'&LPage &P of &N &CFilename: &F &RSheetname: &A'
  50. footer = u'&LCurrent date: &D &RCurrent time: &T'
  51. for sheet in workbook.worksheets():
  52. self.assertEqual(header, sheet.header)
  53. self.assertEqual(footer, sheet.footer)
  54. def test_wrong_options(self):
  55. """
  56. Check that options must be a dict
  57. """
  58. with self.assertRaises(ValidationError):
  59. self.env['report.xlsx.hf'].create({
  60. 'name': 'Header ERROR',
  61. 'hf_type': 'header',
  62. 'value': '&LPage &P of &N &CFilename: &F &RSheetname: &A',
  63. 'manual_options': "1234",
  64. })
  65. def test_image_options(self):
  66. """
  67. Check that, adding image, modify the options
  68. """
  69. header = self.env['report.xlsx.hf'].create({
  70. 'name': 'Header IMAGE',
  71. 'hf_type': 'header',
  72. 'value': '&L&G &C&G &R&G',
  73. 'image_left':
  74. 'R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
  75. 'image_left_name': 'image_left.jpg',
  76. 'image_center':
  77. 'R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
  78. 'image_center_name': 'image_center.jpg',
  79. 'image_right':
  80. 'R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
  81. 'image_right_name': 'image_right.jpg',
  82. })
  83. options = header.get_options()
  84. self.assertEqual(options.get('image_left'), 'image_left.jpg')
  85. self.assertEqual(options.get('image_center'), 'image_center.jpg')
  86. self.assertEqual(options.get('image_right'), 'image_right.jpg')
  87. self.assertTrue(options.get('image_data_left'))
  88. self.assertTrue(options.get('image_data_center'))
  89. self.assertTrue(options.get('image_data_right'))