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.

93 lines
2.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Savoir-faire Linux
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import tests
  5. @tests.at_install(False)
  6. @tests.post_install(True)
  7. class TestMailTemplate(tests.TransactionCase):
  8. def setUp(self):
  9. super(TestMailTemplate, self).setUp()
  10. self.report_view = self.env['ir.ui.view'].create({
  11. 'name': 'test_report_template',
  12. 'mode': 'primary',
  13. 'type': 'qweb',
  14. 'arch': """\
  15. <?xml version="1.0"?>
  16. <t t-name="mail_template_multi_report.test_report_template">
  17. <t t-call="report.html_container">
  18. <t t-call="report.internal_layout">
  19. <div class="page">
  20. </div>
  21. </t>
  22. </t>
  23. </t>
  24. """
  25. })
  26. model_data = self.env['ir.model.data'].create({
  27. 'module': 'mail_template_multi_report',
  28. 'model': 'ir.ui.view',
  29. 'name': 'test_report_template',
  30. 'res_id': self.report_view.id,
  31. })
  32. model_data.clear_caches()
  33. self.report = self.env['ir.actions.report.xml'].create({
  34. 'name': 'Test Report 1',
  35. 'model': 'res.partner',
  36. 'report_type': 'qweb-html',
  37. 'report_name': 'mail_template_multi_report.test_report_template',
  38. })
  39. self.template = self.env['mail.template'].create({
  40. 'name': 'Test Email Template',
  41. 'model_id': self.env.ref('base.model_res_partner').id,
  42. 'report_line_ids': [(0, 0, {
  43. 'report_name': '${object.name}',
  44. 'report_template_id': self.report.id,
  45. })]
  46. })
  47. self.partner = self.env['res.partner'].create({
  48. 'name': 'Test Partner',
  49. 'customer': True,
  50. })
  51. def test_01_generate_email(self):
  52. res = self.template.generate_email([self.partner.id])
  53. self.assertEquals(len(res[self.partner.id]['attachments']), 1)
  54. def test_02_generate_email_with_standard_report(self):
  55. self.template.write({
  56. 'report_name': '${object.name}',
  57. 'report_template': self.report.id,
  58. })
  59. res = self.template.generate_email([self.partner.id])
  60. self.assertEquals(len(res[self.partner.id]['attachments']), 2)
  61. def test_03_report_condition_true(self):
  62. self.template.report_line_ids[0].write({
  63. 'condition': "${object.customer}",
  64. })
  65. res = self.template.generate_email([self.partner.id])
  66. self.assertEquals(len(res[self.partner.id]['attachments']), 1)
  67. def test_04_report_condition_false(self):
  68. self.template.report_line_ids[0].write({
  69. 'condition': "${object.supplier}",
  70. })
  71. res = self.template.generate_email([self.partner.id])
  72. res[self.partner.id].setdefault('attachments', [])
  73. self.assertEquals(len(res[self.partner.id]['attachments']), 0)