summaryrefslogtreecommitdiff
path: root/addons/mail/wizard/mail_compose_message.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-05-03 16:31:19 +0200
committerThibault Delavallée <tde@odoo.com>2018-05-07 11:00:03 +0200
commit324ae5ed8fbe833200a256d92e7225d2e27f096a (patch)
tree59d42d87e58b3dcccb135071900517eef63fd370 /addons/mail/wizard/mail_compose_message.py
parent282733cf8df7bfe7cae17fd726d1caf759690169 (diff)
[REF] mail: get rid of thread_model context key
message_post and various mail.thread related code still support a thread_model context key allowing to redirect message post on another model. Purpose of this commit is to get rid of that context key and support model / res_id fields coming from either the record on which we run, either parameters of message_post. Indeed those parameter match the one used as fields on mail message. It makes sense to support them for customization if necessary instead of using a context key. This context key exists since a lot of time. It is difficult to find the source as history is quite complex when the mail was refactored in 2012. See notably 6aa4f80b2d9696a8dcbcc970bbd656b5842b02d4 and 2c4ed841b915cef42fe1f65d27427b7d86d659cd for example.
Diffstat (limited to 'addons/mail/wizard/mail_compose_message.py')
-rw-r--r--addons/mail/wizard/mail_compose_message.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index 91718f21f8a..e16cd71815b 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -216,9 +216,7 @@ class MailComposer(models.TransientModel):
mass_mode = wizard.composition_mode in ('mass_mail', 'mass_post')
Mail = self.env['mail.mail']
- ActiveModel = self.env[wizard.model if wizard.model else 'mail.thread']
- if not hasattr(ActiveModel, 'message_post'):
- ActiveModel = self.env['mail.thread'].with_context(thread_model=wizard.model)
+ ActiveModel = self.env[wizard.model] if wizard.model and hasattr(self.env[wizard.model], 'message_post') else self.env['mail.thread']
if wizard.composition_mode == 'mass_post':
# do not send emails directly but use the queue instead
# add context key to avoid subscribing the author
@@ -248,7 +246,7 @@ class MailComposer(models.TransientModel):
if wizard.composition_mode == 'mass_mail':
batch_mails |= Mail.create(mail_values)
else:
- ActiveModel.browse(res_id).message_post(
+ post_params = dict(
message_type=wizard.message_type,
subtype_id=subtype_id,
notif_layout=notif_layout,
@@ -257,6 +255,9 @@ class MailComposer(models.TransientModel):
'mail_auto_delete': wizard.template_id.auto_delete if wizard.template_id else False,
},
**mail_values)
+ if ActiveModel._name == 'mail.thread' and wizard.model:
+ post_params['model'] = wizard.model
+ ActiveModel.browse(res_id).message_post(**post_params)
if wizard.composition_mode == 'mass_mail':
batch_mails.send(auto_commit=auto_commit)