[FIX] mail: mail_template: fixed create_action method that creates the
more menu action linked to an email template. [TESTS] mail: added a test for this method.
This commit is contained in:
@@ -227,38 +227,33 @@ class MailTemplate(models.Model):
|
||||
|
||||
@api.multi
|
||||
def create_action(self):
|
||||
ActWindow = self.env['ir.actions.act_window'].sudo()
|
||||
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
ActWindowSudo = self.env['ir.actions.act_window'].sudo()
|
||||
IrValuesSudo = self.env['ir.values'].sudo()
|
||||
view = self.env.ref('mail.email_compose_message_wizard_form')
|
||||
|
||||
for template in self:
|
||||
src_obj = template.model_id.model
|
||||
model_data_id = data_obj._get_id(cr, uid, 'mail', 'email_compose_message_wizard_form')
|
||||
res_id = data_obj.browse(cr, uid, model_data_id, context=context).res_id
|
||||
button_name = _('Send Mail (%s)') % template.name
|
||||
act_id = action_obj.create(cr, SUPERUSER_ID, {
|
||||
'name': button_name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'mail.compose.message',
|
||||
'src_model': src_obj,
|
||||
'view_type': 'form',
|
||||
'context': "{'default_composition_mode': 'mass_mail', 'default_template_id' : %d, 'default_use_template': True}" % (template.id),
|
||||
'view_mode':'form,tree',
|
||||
'view_id': res_id,
|
||||
'target': 'new',
|
||||
'auto_refresh':1
|
||||
}, context)
|
||||
ir_values_id = self.pool.get('ir.values').create(cr, SUPERUSER_ID, {
|
||||
'name': button_name,
|
||||
'model': src_obj,
|
||||
'key2': 'client_action_multi',
|
||||
'value': "ir.actions.act_window,%s" % act_id,
|
||||
'object': True,
|
||||
}, context)
|
||||
|
||||
button_name = _('Send Mail (%s)') % template.name
|
||||
action = ActWindowSudo.create({
|
||||
'name': button_name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'mail.compose.message',
|
||||
'src_model': src_obj,
|
||||
'view_type': 'form',
|
||||
'context': "{'default_composition_mode': 'mass_mail', 'default_template_id' : %d, 'default_use_template': True}" % (template.id),
|
||||
'view_mode': 'form,tree',
|
||||
'view_id': view.id,
|
||||
'target': 'new',
|
||||
'auto_refresh': 1})
|
||||
ir_value = IrValuesSudo.create({
|
||||
'name': button_name,
|
||||
'model': src_obj,
|
||||
'key2': 'client_action_multi',
|
||||
'value': "ir.actions.act_window,%s" % action.id})
|
||||
template.write({
|
||||
'ref_ir_act_window': act_id,
|
||||
'ref_ir_value': ir_values_id,
|
||||
'ref_ir_act_window': action.id,
|
||||
'ref_ir_value': ir_value.id,
|
||||
})
|
||||
|
||||
return True
|
||||
|
||||
@@ -128,3 +128,15 @@ class TestMailTemplate(TestMail):
|
||||
last_template = self.env['mail.template'].search([('model', '=', 'mail.group'), ('subject', '=', 'Forget me subject')], limit=1)
|
||||
self.assertEqual(last_template.body_html, '<p>Dummy body</p>', 'email_template incorrect body_html')
|
||||
|
||||
def test_add_context_action(self):
|
||||
self.email_template.create_action()
|
||||
|
||||
# check template act_window and ir_values has been updated
|
||||
self.assertTrue(bool(self.email_template.ref_ir_act_window))
|
||||
self.assertTrue(bool(self.email_template.ref_ir_value))
|
||||
|
||||
# check those records
|
||||
action = self.email_template.ref_ir_act_window
|
||||
self.assertEqual(action.name, 'Send Mail (%s)' % self.email_template.name)
|
||||
value = self.email_template.ref_ir_value
|
||||
self.assertEqual(value.name, 'Send Mail (%s)' % self.email_template.name)
|
||||
|
||||
Reference in New Issue
Block a user