[FIX] email_template: correct creation/deletion of context action
bzr revid: chs@openerp.com-20130613143931-tpnx0diyvkovr2xe
This commit is contained in:
parent
180e6e41d8
commit
448e19e550
|
@ -26,7 +26,6 @@ import logging
|
||||||
import openerp
|
import openerp
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
from openerp.osv import osv, fields
|
from openerp.osv import osv, fields
|
||||||
from openerp.osv import fields
|
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
from urllib import urlencode, quote as quote
|
from urllib import urlencode, quote as quote
|
||||||
|
@ -192,7 +191,6 @@ class email_template(osv.osv):
|
||||||
}
|
}
|
||||||
|
|
||||||
def create_action(self, cr, uid, ids, context=None):
|
def create_action(self, cr, uid, ids, context=None):
|
||||||
vals = {}
|
|
||||||
action_obj = self.pool.get('ir.actions.act_window')
|
action_obj = self.pool.get('ir.actions.act_window')
|
||||||
data_obj = self.pool.get('ir.model.data')
|
data_obj = self.pool.get('ir.model.data')
|
||||||
for template in self.browse(cr, uid, ids, context=context):
|
for template in self.browse(cr, uid, ids, context=context):
|
||||||
|
@ -200,7 +198,7 @@ class email_template(osv.osv):
|
||||||
model_data_id = data_obj._get_id(cr, uid, 'mail', 'email_compose_message_wizard_form')
|
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
|
res_id = data_obj.browse(cr, uid, model_data_id, context=context).res_id
|
||||||
button_name = _('Send Mail (%s)') % template.name
|
button_name = _('Send Mail (%s)') % template.name
|
||||||
vals['ref_ir_act_window'] = action_obj.create(cr, SUPERUSER_ID, {
|
act_id = action_obj.create(cr, SUPERUSER_ID, {
|
||||||
'name': button_name,
|
'name': button_name,
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'res_model': 'mail.compose.message',
|
'res_model': 'mail.compose.message',
|
||||||
|
@ -212,27 +210,29 @@ class email_template(osv.osv):
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
'auto_refresh':1
|
'auto_refresh':1
|
||||||
}, context)
|
}, context)
|
||||||
vals['ref_ir_value'] = self.pool.get('ir.values').create(cr, SUPERUSER_ID, {
|
ir_values_id = self.pool.get('ir.values').create(cr, SUPERUSER_ID, {
|
||||||
'name': button_name,
|
'name': button_name,
|
||||||
'model': src_obj,
|
'model': src_obj,
|
||||||
'key2': 'client_action_multi',
|
'key2': 'client_action_multi',
|
||||||
'value': "ir.actions.act_window," + str(vals['ref_ir_act_window']),
|
'value': "ir.actions.act_window,%s" % act_id,
|
||||||
'object': True,
|
'object': True,
|
||||||
}, context)
|
}, context)
|
||||||
self.write(cr, uid, ids, {
|
|
||||||
'ref_ir_act_window': vals.get('ref_ir_act_window',False),
|
template.write({
|
||||||
'ref_ir_value': vals.get('ref_ir_value',False),
|
'ref_ir_act_window': act_id,
|
||||||
}, context)
|
'ref_ir_value': ir_values_id,
|
||||||
|
})
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def unlink_action(self, cr, uid, ids, context=None):
|
def unlink_action(self, cr, uid, ids, context=None):
|
||||||
for template in self.browse(cr, uid, ids, context=context):
|
for template in self.browse(cr, uid, ids, context=context):
|
||||||
try:
|
try:
|
||||||
if template.ref_ir_act_window:
|
if template.ref_ir_act_window:
|
||||||
self.pool.get('ir.actions.act_window').unlink(cr, uid, template.ref_ir_act_window.id, context)
|
self.pool.get('ir.actions.act_window').unlink(cr, SUPERUSER_ID, template.ref_ir_act_window.id, context)
|
||||||
if template.ref_ir_value:
|
if template.ref_ir_value:
|
||||||
ir_values_obj = self.pool.get('ir.values')
|
ir_values_obj = self.pool.get('ir.values')
|
||||||
ir_values_obj.unlink(cr, uid, template.ref_ir_value.id, context)
|
ir_values_obj.unlink(cr, SUPERUSER_ID, template.ref_ir_value.id, context)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
|
raise osv.except_osv(_("Warning"), _("Deletion of the action record failed."))
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue