summaryrefslogtreecommitdiff
path: root/addons/mail/wizard/mail_compose_message.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-11-19 15:24:31 +0000
committerThibault Delavallée <tde@odoo.com>2020-11-26 08:47:13 +0000
commit1c8ca358d75c9fe00631731d5061674c0a3a040b (patch)
treebb6ee7ce887b32cf92720cfbcf6a3c4c645a1d77 /addons/mail/wizard/mail_compose_message.py
parent92ff1379b0492765fd0ba9863a9ce13fba7eeb4a (diff)
[FIX] mail: fix composer default values computation
As default is called numerous times with sometimes all fields, sometimes only one field we have to ensure we avoid computing and setting unnecessary or wrong values. We suspect this comes from default_get being called more often at creation time since Odoo v14. Default values for some fields in mail composer are dependent on each other. Especially composition mode and model / res_id(s) are important for some fields as behavior is not the same in comment or mass mail mode (subject set / not set, template values rendered / displayed raw, ...). Especially subject is wrongly computed in mass mail mode. For example use a mass mail composer action on leads without template. Indeed a default_get is called on subject alone. As web client adds active_model / active_id automatically default returns a value for subject while it should not as other values (model, res_id) are not asked and therefore not correctly computed. It makes composer compute values in comment mode while it should stay in mass mode. In this commit we fix that behavior by * computing only requested values (better match returned values and asked fields); * avoid computing values if context values are not given (model, res_id or res_ids, composition_mode); Task ID-2390314 PR odoo/odoo#62061 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/mail/wizard/mail_compose_message.py')
-rw-r--r--addons/mail/wizard/mail_compose_message.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index d5800ded589..8c84376356b 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -63,25 +63,22 @@ class MailComposer(models.TransientModel):
if missing_author:
result['author_id'] = author_id
- result['composition_mode'] = result.get('composition_mode', 'comment')
- result['model'] = result.get('model', self._context.get('active_model'))
- result['res_id'] = result.get('res_id', self._context.get('active_id'))
- if 'no_auto_thread' not in result and (result['model'] not in self.env or not hasattr(self.env[result['model']], 'message_post')):
- result['no_auto_thread'] = True
+ if 'model' in fields and 'model' not in result:
+ result['model'] = self._context.get('active_model')
+ if 'res_id' in fields and 'res_id' not in result:
+ result['res_id'] = self._context.get('active_id')
+ if 'no_auto_thread' in fields and 'no_auto_thread' not in result and result.get('model'):
+ # doesn't support threading
+ if result['model'] not in self.env or not hasattr(self.env[result['model']], 'message_post'):
+ result['no_auto_thread'] = True
- vals = {}
if 'active_domain' in self._context: # not context.get() because we want to keep global [] domains
- vals['active_domain'] = '%s' % self._context.get('active_domain')
- if result['composition_mode'] == 'comment':
- vals.update(self.get_record_data(result))
+ result['active_domain'] = '%s' % self._context.get('active_domain')
+ if result.get('composition_mode') == 'comment' and (set(fields) & set(['model', 'res_id', 'partner_ids', 'record_name', 'subject'])):
+ result.update(self.get_record_data(result))
- for field in vals:
- if field in fields:
- result[field] = vals[field]
-
- if fields is not None:
- [result.pop(field, None) for field in list(result) if field not in fields]
- return result
+ filtered_result = dict((fname, result[fname]) for fname in result if fname in fields)
+ return filtered_result
# content
subject = fields.Char('Subject')