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.

96 lines
3.0 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 openerp.tests import common
  5. class TestEmailTemplate(common.TransactionCase):
  6. def setUp(self):
  7. super(TestEmailTemplate, 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['email.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_batch(self):
  50. res = self.env['email.template'].generate_email_batch(
  51. self.template.id, [self.partner.id])
  52. self.assertEquals(len(res[self.partner.id]['attachments']), 1)
  53. def test_02_generate_email_batch_with_standard_report(self):
  54. self.template.write({
  55. 'report_name': '${object.name}',
  56. 'report_template': self.report.id,
  57. })
  58. res = self.env['email.template'].generate_email_batch(
  59. self.template.id, [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.env['email.template'].generate_email_batch(
  66. self.template.id, [self.partner.id])
  67. self.assertEquals(len(res[self.partner.id]['attachments']), 1)
  68. def test_04_report_condition_false(self):
  69. self.template.report_line_ids[0].write({
  70. 'condition': "${object.supplier}",
  71. })
  72. res = self.env['email.template'].generate_email_batch(
  73. self.template.id, [self.partner.id])
  74. res[self.partner.id].setdefault('attachments', [])
  75. self.assertEquals(len(res[self.partner.id]['attachments']), 0)