summaryrefslogtreecommitdiff
path: root/addons/mail/wizard/mail_compose_message.py
diff options
context:
space:
mode:
authorJérome Maes <jem@openerp.com>2015-09-02 14:57:30 +0200
committerJérome Maes <jem@openerp.com>2015-09-04 15:55:38 +0200
commit7674536713aaa3721ddb55e43ddf50585a4f20a0 (patch)
tree0107290d2db4403bb750664d9857ea262a537da9 /addons/mail/wizard/mail_compose_message.py
parent5f8663cdb6758d9a7b2d7aee7c92a627f8b463ee (diff)
[IMP] mail : message_post_with_template helper
Create `message_post_with_template` helper method to factorize the simulation of a mail.compose.message wizard. Also, fix the generated attachments of mail.compose.message wizard by returning ORM command (6, 0, ids) instead of the list of attachments ids. In order to standardize the behavior of the wizard, and since the ORM support command assignation in onchange api.v8, all the x2many fields of the wizard return a command. FYI, that was tde's idea !
Diffstat (limited to 'addons/mail/wizard/mail_compose_message.py')
-rw-r--r--addons/mail/wizard/mail_compose_message.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index 2c7c5b7894d..ac6953af348 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -94,18 +94,8 @@ class MailComposer(models.TransientModel):
result['model'] = 'res.partner'
result['res_id'] = self.env.user.partner_id.id
- # Override to pre-fill the data when having a template in single-email mode
- # and not going through the view: the on_change is not called in that case.
- if result.get('composition_mode') != 'mass_mail' and self._context.get('default_template_id') and result.get('model') and result.get('res_id'):
- result.update(
- self.onchange_template_id(
- self._context['default_template_id'], result.get('composition_mode'),
- result.get('model'), result.get('res_id')
- )['value']
- )
if fields is not None:
[result.pop(field, None) for field in result.keys() if field not in fields]
-
return result
@api.model
@@ -330,7 +320,7 @@ class MailComposer(models.TransientModel):
#------------------------------------------------------
@api.multi
- @api.onchange('template_id', 'composition_mode', 'model', 'res_id')
+ @api.onchange('template_id')
def onchange_template_id_wrapper(self):
self.ensure_one()
values = self.onchange_template_id(self.template_id.id, self.composition_mode, self.model, self.res_id)['value']
@@ -340,7 +330,9 @@ class MailComposer(models.TransientModel):
@api.multi
def onchange_template_id(self, template_id, composition_mode, model, res_id):
""" - mass_mailing: we cannot render, so return the template values
- - normal mode: return rendered values """
+ - normal mode: return rendered values
+ /!\ for x2many field, this onchange return command instead of ids
+ """
if template_id and composition_mode == 'mass_mail':
template = self.env['mail.template'].browse(template_id)
fields = ['subject', 'body_html', 'email_from', 'reply_to', 'mail_server_id']
@@ -373,6 +365,15 @@ class MailComposer(models.TransientModel):
if values.get('body_html'):
values['body'] = values.pop('body_html')
+
+ # This onchange should return command instead of ids for x2many field.
+ # ORM handle the assignation of command list on new onchange (api.v8),
+ # this force the complete replacement of x2many field with the (6, 0, ids)
+ # command and is compatible with onchange api.v7
+ for field_name in values.keys():
+ if self._fields[field_name].type == 'many2many' or self._fields[field_name].type == 'one2many':
+ values[field_name] = [(6, 0, values[field_name])]
+
return {'value': values}
@api.multi