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.

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