summaryrefslogtreecommitdiff
path: root/addons/test_mail/tests/test_mail_template.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-05-29 14:06:12 +0200
committerChristophe Simonis <chs@odoo.com>2019-05-29 14:06:12 +0200
commit8d7ee3921384ce070d3333cbc4073ffc4f8febc4 (patch)
tree197e81ea4c35bc56a898d63add666d53ea79f15b /addons/test_mail/tests/test_mail_template.py
parent7ca0fe3c9f1050eac2d117ea35fd7414d1b0742f (diff)
parent8a0e819d0bb0e4184ed64559b7be91605d044e19 (diff)
[MERGE] forward port branch saas-11.3 up to 8a0e819d0bb
Diffstat (limited to 'addons/test_mail/tests/test_mail_template.py')
-rw-r--r--addons/test_mail/tests/test_mail_template.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/addons/test_mail/tests/test_mail_template.py b/addons/test_mail/tests/test_mail_template.py
index d899c6829b4..1521033e8c6 100644
--- a/addons/test_mail/tests/test_mail_template.py
+++ b/addons/test_mail/tests/test_mail_template.py
@@ -72,6 +72,46 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients):
body_content=self.test_record.email_from,
attachments=[('first.txt', b'My first attachment', 'text/plain'), ('second.txt', b'My second attachment', 'text/plain')])
+ def test_composer_template_onchange_attachments(self):
+ """Tests that all attachments are added to the composer,
+ static attachments are not duplicated and while reports are re-generated,
+ and that intermediary attachments are dropped."""
+
+ composer = self.env['mail.compose.message'].with_context(default_attachment_ids=[]).create({})
+ report_template = self.env.ref('web.action_report_externalpreview')
+ template_1 = self.email_template.copy({
+ 'report_template': report_template.id,
+ })
+ template_2 = self.email_template.copy({
+ 'attachment_ids': False,
+ 'report_template': report_template.id,
+ })
+
+ onchange_templates = [template_1, template_2, template_1, False]
+ attachments_onchange = [composer.attachment_ids]
+ # template_1 has two static attachments and one dynamically generated report,
+ # template_2 only has the report, so we should get 3, 1, 3 attachments
+ attachment_numbers = [0, 3, 1, 3, 0]
+
+ with self.env.do_in_onchange():
+ for template in onchange_templates:
+ onchange = composer.onchange_template_id(
+ template.id if template else False, 'comment', self.test_record._name, self.test_record.id
+ )
+ values = composer._convert_to_record(composer._convert_to_cache(onchange['value']))
+ attachments_onchange.append(values['attachment_ids'])
+ composer.update(onchange['value'])
+
+ self.assertEqual(
+ [len(attachments) for attachments in attachments_onchange],
+ attachment_numbers,
+ )
+
+ self.assertTrue(
+ len(attachments_onchange[1] & attachments_onchange[3]) == 2,
+ "The two static attachments on the template should be common to the two onchanges"
+ )
+
@mute_logger('odoo.addons.mail.models.mail_mail')
def test_post_post_w_template(self):
self.test_record.sudo(self.user_employee).message_post_with_template(self.email_template.id, composition_mode='comment')