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.

44 lines
1.9 KiB

  1. # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. class TestAttachExistingAttachment(common.TransactionCase):
  5. def setUp(self):
  6. super(TestAttachExistingAttachment, self).setUp()
  7. self.partner_obj = self.env['res.partner']
  8. self.partner_01 = self.env.ref('base.res_partner_10')
  9. self.partner_02 = self.env.ref('base.res_partner_address_17')
  10. def test_send_email_attachment(self):
  11. ctx = self.env.context.copy()
  12. ctx.update({
  13. 'default_model': 'res.partner',
  14. 'default_res_id': self.partner_01.id,
  15. 'default_composition_mode': 'comment',
  16. })
  17. mail_compose = self.env['mail.compose.message']
  18. values = mail_compose.with_context(ctx)\
  19. .onchange_template_id(False, 'comment', 'res.partner',
  20. self.partner_01.id)['value']
  21. values['partner_ids'] = [(4, self.partner_02.id)]
  22. compose_id = mail_compose.with_context(ctx).create(values)
  23. compose_id.autofollow_recipients = False
  24. compose_id.with_context(ctx).send_mail()
  25. res = self.env["mail.followers"].search(
  26. [('res_model', '=', 'res.partner'),
  27. ('res_id', '=', self.partner_01.id),
  28. ('partner_id', '=', self.partner_02.id)])
  29. # I check if the recipient isn't a follower
  30. self.assertEqual(len(res.ids), 0)
  31. compose_id = mail_compose.with_context(ctx).create(values)
  32. compose_id.autofollow_recipients = True
  33. compose_id.with_context(ctx).send_mail()
  34. res = self.env["mail.followers"].search(
  35. [('res_model', '=', 'res.partner'),
  36. ('res_id', '=', self.partner_01.id),
  37. ('partner_id', '=', self.partner_02.id)])
  38. # I check if the recipient is a follower
  39. self.assertEqual(len(res.ids), 1)