From 88e712202020d3da0569991bc08e710bf962112e Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 2 Mar 2016 19:13:28 +0100 Subject: [PATCH] [FIX] mail: mail_server_id When a specific SMTP server is set on a mail template, it is never used when the mail is sent. There are two reasons: - `mail_server_id` is a read-only field set by an onchange. However, a read-only field is not sent to the server, so the information is lost. - The information is stored in the context of the object `Mail`, but it is never used. Moreover, when the method `message_post` is called, the `Mail` object is not used to post the message, so the information is lost again. The fix includes two parts: - the `mail_server_id` field is not read-only anymore. Actually, there is no reason to make it read-only. - the information is stored directly in the mail values and used at the appropriate moment. Fixes #6554 (from v9.0) opw-669958 --- addons/mail/models/mail_message.py | 2 +- addons/mail/models/res_partner.py | 1 + addons/mail/wizard/mail_compose_message.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index fe1fc7a1141..6e97df905cb 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -110,7 +110,7 @@ class Message(models.Model): help='Answers do not go in the original document discussion thread. This has an impact on the generated message-id.') message_id = fields.Char('Message-Id', help='Message unique identifier', select=1, readonly=1, copy=False) reply_to = fields.Char('Reply-To', help='Reply email address. Setting the reply_to bypasses the automatic thread creation.') - mail_server_id = fields.Many2one('ir.mail_server', 'Outgoing mail server', readonly=1) + mail_server_id = fields.Many2one('ir.mail_server', 'Outgoing mail server') @api.multi def _get_needaction(self): diff --git a/addons/mail/models/res_partner.py b/addons/mail/models/res_partner.py index e64c2bdfa1e..a44920a5b92 100644 --- a/addons/mail/models/res_partner.py +++ b/addons/mail/models/res_partner.py @@ -93,6 +93,7 @@ class Partner(models.Model): mail_values = { 'mail_message_id': message.id, + 'mail_server_id': message.mail_server_id.id, 'auto_delete': self._context.get('mail_auto_delete', True), 'references': references, } diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index cc2dff25f38..158507a2530 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -216,7 +216,7 @@ class MailComposer(models.TransientModel): if wizard.template_id: # template user_signature is added when generating body_html # mass mailing: use template auto_delete value -> note, for emails mass mailing only - Mail = Mail.with_context(mail_notify_user_signature=False, mail_server_id=wizard.template_id.mail_server_id.id) + Mail = Mail.with_context(mail_notify_user_signature=False) ActiveModel = ActiveModel.with_context(mail_notify_user_signature=False, mail_auto_delete=wizard.template_id.auto_delete) if not hasattr(ActiveModel, 'message_post'): ActiveModel = self.env['mail.thread'].with_context(thread_model=wizard.model) @@ -282,6 +282,7 @@ class MailComposer(models.TransientModel): 'email_from': self.email_from, 'record_name': self.record_name, 'no_auto_thread': self.no_auto_thread, + 'mail_server_id': self.mail_server_id.id, } # mass mailing: rendering override wizard static values if mass_mail_mode and self.model: