Skip to content
Snippets Groups Projects
Commit 0300e0b7 authored by Christophe Matthieu's avatar Christophe Matthieu
Browse files

[FIX] mail: onchange_template_id return a valid command of commands

Use convert_to_cache and convert_to_read to format onchange values.
Fix: default value can be a command list, the onchange convert the comand list into a wrong comand list of command list.
parent 9c7d3662
No related branches found
No related tags found
No related merge requests found
......@@ -50,9 +50,11 @@ class TestMailTemplate(TestMail):
}).create({'subject': 'Forget me subject', 'body': 'Dummy body'})
values = composer.onchange_template_id(self.email_template.id, 'comment', 'mail.channel', self.group_pigs.id)['value']
# this onchange return command [(6, 0, ids)] for x2many fields
recipients = self.env['res.partner'].browse(values['partner_ids'][0][2])
attachments = self.env['ir.attachment'].browse(values['attachment_ids'][0][2])
# use _convert_to_cache to return a browse record list from command list or id list for x2many fields
values = self.env['mail.compose.message']._convert_to_cache(values)
recipients = values['partner_ids']
attachments = values['attachment_ids']
test_recipients = self.env['res.partner'].search([('email', 'in', ['test1@example.com', 'test2@example.com'])]) | self.partner_1 | self.partner_2 | self.user_employee.partner_id
test_attachments = self.env['ir.attachment'].search([('name', 'in', ['_Test_First', '_Test_Second'])])
self.assertEqual(values['subject'], self.group_pigs.name)
......
......@@ -368,11 +368,9 @@ class MailComposer(models.TransientModel):
# 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)
# this force the complete replacement of x2many field with
# 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])]
values = self._convert_to_write(self._convert_to_cache(values))
return {'value': values}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment