summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorNans Lefebvre <len@odoo.com>2019-05-21 11:44:12 +0000
committerNans Lefebvre <len@odoo.com>2019-05-24 13:45:50 +0000
commit4c3698aa3f0a6a674d0a452e9a85909f727e057f (patch)
treec840455ff85e684897981b2eb381f18b9b2ef292 /addons
parentb45236dd688d7b7054412ae96d755a03a7590b91 (diff)
[FIX] mail: add all attachments at template onchange
Fine-tuning of 516f22c3987. This commit missed attachments that are linked to a mail.template, which should be added to every mail sent using the template. To make sure that we both fix the duplicates and the generation issue, we add a test. opw 2000515 opw 1998782 closes odoo/odoo#33653 Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/mail/wizard/mail_compose_message.py1
-rw-r--r--addons/test_mail/tests/test_mail_template.py40
2 files changed, 41 insertions, 0 deletions
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index dcaf346e139..913ca46bce9 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -414,6 +414,7 @@ class MailComposer(models.TransientModel):
# ORM handle the assignation of command list on new onchange (api.v8),
# this force the complete replacement of x2many field with
# command and is compatible with onchange api.v7
+ attachment_ids += values.pop('attachment_ids' , [])
values = self._convert_to_write(values)
if attachment_ids:
values.update(attachment_ids=[(6, 0, attachment_ids)])
diff --git a/addons/test_mail/tests/test_mail_template.py b/addons/test_mail/tests/test_mail_template.py
index e1b14d57a20..4258fff577b 100644
--- a/addons/test_mail/tests/test_mail_template.py
+++ b/addons/test_mail/tests/test_mail_template.py
@@ -236,3 +236,43 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients):
new_partner = Partner.search([('email', '=', email_new_partner)])
self.assertTrue(new_partner)
self.assertEqual(new_partner.company_id, company1)
+
+ 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'].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]
+ attachments_onchange = []
+ # 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 = [3, 1, 3]
+
+ for template in onchange_templates:
+ onchange = composer.onchange_template_id(
+ template.id, 'comment', 'mail.test', self.test_record.id
+ )
+ values = composer._convert_to_record(composer._convert_to_cache(onchange['value']))
+ attachments = values['attachment_ids']
+ composer.attachment_ids = attachments # we apply the onchange
+ attachments_onchange.append(attachments)
+
+ self.assertEqual(
+ [len(attachments) for attachments in attachments_onchange],
+ attachment_numbers,
+ )
+
+ self.assertTrue(
+ len(attachments_onchange[0] & attachments_onchange[2]) == 2,
+ "The two static attachments on the template should be common to the two onchanges"
+ )