我尝试在我的自定义模块中显示一个名为' xx_project'
的自定义消息框以下代码来自我制作的包含警告的类。然后我想从我的自定义模块' xx_project'
中调用此警告class warning(osv.osv_memory):
_name = 'warning'
_description = 'warning'
_columns = {
'type': fields.selection(WARNING_TYPES, string='Type', readonly=True),
'title': fields.char(string="Title", size=100, readonly=True),
'message': fields.text(string="Message", readonly=True),
}
_req_name = 'title'
def _get_view_id(self, cr, uid):
"""Get the view id
@return: view id, or False if no view found
"""
res = self.pool.get('ir.model.data').get_object_reference(cr, uid,
'xx_project', 'warning_form')
return res and res[1] or False
def message(self, cr, uid, id, context):
message = self.browse(cr, uid, id)
message_type = [t[1] for t in WARNING_TYPES if message.type == t[0]][0]
print '%s: %s' % (_(message_type), _(message.title))
res = {
'name': '%s: %s' % (_(message_type), _(message.title)),
'view_type': 'form',
'view_mode': 'form',
'view_id': self._get_view_id(cr, uid),
'res_model': 'warning',
'domain': [],
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
'res_id': message.id
}
return res
def info(self, cr, uid, title, message, context=None):
id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'info'})
res = self.message(cr, uid, id, context)
return res
最后在xx_project中我有一个名为' xx_message'调用函数' get_message'。
get_message看起来像这样:
def get_message(self, cr, uid, ids, name, args, context=None):
return self.pool.get('warning').info(cr, uid, title='Export imformation',
message="%s products Created, %s products Updated " % (
"test", "test"))
和' xx_message':
_columns = {
'xx_message': fields.function(get_message)
}
当我尝试运行此代码时,我一直在收到Keyerror吗?