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.

68 lines
2.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Eficent Business and IT Consulting Services S.L.
  3. # (http://www.eficent.com)
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from odoo.tests.common import TransactionCase
  6. class TestCustomerActivityStatement(TransactionCase):
  7. """
  8. Tests for Customer Activity Statement.
  9. """
  10. def setUp(self):
  11. super(TestCustomerActivityStatement, self).setUp()
  12. self.res_users_model = self.env['res.users']
  13. self.company = self.env.ref('base.main_company')
  14. self.partner1 = self.env.ref('base.res_partner_1')
  15. self.partner2 = self.env.ref('base.res_partner_2')
  16. self.g_account_user = self.env.ref('account.group_account_user')
  17. self.user = self._create_user('user_1', [self.g_account_user],
  18. self.company).id
  19. self.statement_model = \
  20. self.env['report.customer_activity_statement.statement']
  21. self.wiz = self.env['customer.activity.statement.wizard']
  22. self.report_name = 'customer_activity_statement.statement'
  23. self.report_title = 'Customer Activity Statement'
  24. def _create_user(self, login, groups, company):
  25. group_ids = [group.id for group in groups]
  26. user = self.res_users_model.create({
  27. 'name': login,
  28. 'login': login,
  29. 'password': 'demo',
  30. 'email': 'example@yourcompany.com',
  31. 'company_id': company.id,
  32. 'company_ids': [(4, company.id)],
  33. 'groups_id': [(6, 0, group_ids)]
  34. })
  35. return user
  36. def test_customer_activity_statement(self):
  37. wiz_id = self.wiz.with_context(
  38. active_ids=[self.partner1.id, self.partner2.id],
  39. ).create({})
  40. statement = wiz_id.button_export_pdf()
  41. self.assertDictContainsSubset(
  42. {
  43. 'type': 'ir.actions.report.xml',
  44. 'report_name': self.report_name,
  45. 'report_type': 'qweb-pdf',
  46. },
  47. statement,
  48. 'There was an error and the PDF report was not generated.'
  49. )
  50. data = wiz_id._prepare_activity_statement()
  51. docids = data['partner_ids']
  52. report = self.statement_model.render_html(docids, data)
  53. self.assertIsInstance(report, str,
  54. "There was an error while compiling the report.")
  55. self.assertIn("<!DOCTYPE html>", report,
  56. "There was an error while compiling the report.")