[FIX] email-template: attachments should have correct model and res_id from template.
bzr revid: tde@openerp.com-20130228144630-7x6kh5jcn4w557do
This commit is contained in:
@@ -375,6 +375,7 @@ class email_template(osv.osv):
|
||||
values = self.generate_email(cr, uid, template_id, res_id, context=context)
|
||||
assert values.get('email_from'), 'email_from is missing or empty after template rendering, send_mail() cannot proceed'
|
||||
del values['email_recipients'] # TODO Properly use them.
|
||||
template = self.get_email_template(cr, uid, template_id, res_id, context=context)
|
||||
|
||||
# manage attachments
|
||||
attachment_ids = values.pop('attachment_ids', [])
|
||||
@@ -384,8 +385,8 @@ class email_template(osv.osv):
|
||||
'name': attachment[0],
|
||||
'datas_fname': attachment[0],
|
||||
'datas': attachment[1],
|
||||
'res_model': values.get('model', False),
|
||||
'res_id': values.get('res_id', False),
|
||||
'res_model': template.model,
|
||||
'res_id': res_id,
|
||||
}
|
||||
context.pop('default_type', None)
|
||||
attachment_ids.append(ir_attachment.create(cr, uid, attachment_data, context=context))
|
||||
|
||||
@@ -48,8 +48,8 @@ class test_message_compose(TestMailBase):
|
||||
_body_html1 = 'Fans of Pigs, unite !'
|
||||
_body_html2 = 'I am angry !'
|
||||
_attachments = [
|
||||
{'name': 'First', 'datas_fname': 'first.txt', 'datas': base64.b64encode('My first attachment')},
|
||||
{'name': 'Second', 'datas_fname': 'second.txt', 'datas': base64.b64encode('My second attachment')}
|
||||
{'name': 'First', 'datas_fname': 'first.txt', 'datas': base64.b64encode('My first attachment'), 'res_model': 'dummy.model'},
|
||||
{'name': 'Second', 'datas_fname': 'second.txt', 'datas': base64.b64encode('My second attachment'), 'res_model': 'dummy.model'}
|
||||
]
|
||||
_attachments_test = [('first.txt', 'My first attachment'), ('second.txt', 'My second attachment')]
|
||||
|
||||
@@ -118,7 +118,7 @@ class test_message_compose(TestMailBase):
|
||||
# Test: mail.compose.message: attachments
|
||||
# Test: mail.message: attachments
|
||||
for attach in compose.attachment_ids:
|
||||
self.assertEqual(attach.res_model, 'mail.group', 'mail.message attachment res_model incorrect')
|
||||
self.assertEqual(attach.res_model, 'dummy.model', 'mail.message attachment res_model through templat was overriden')
|
||||
self.assertEqual(attach.res_id, self.group_pigs_id, 'mail.message attachment res_id incorrect')
|
||||
self.assertIn((attach.name, base64.b64decode(attach.datas)), _attachments_test,
|
||||
'mail.message attachment name / data incorrect')
|
||||
|
||||
Reference in New Issue
Block a user