Openerp显示消息对话框

时间:2015-04-18 07:35:38

标签: openerp

如何在openerp中显示消息框?我正在使用这样的加薪:

raise osv.except_osv(_("Warning!"), _("Error"))

但这会停止执行其他代码,我只想显示一个信息性消息框。

2 个答案:

答案 0 :(得分:2)

提升osv.except_osv会做一些事情:

1)中断当前处理(毕竟它是一个python异常)。

2)导致OpenERP回滚当前数据库事务。

3)使OpenERP向用户显示一个对话框,而不是转储堆栈跟踪并给用户一个"发生的坏事"消息。

对于onchange我们可以返回

warning = {
        'title': 'Warning!',
        'message' : 'Your message.'
    }
return {'warning': warning}

但它不适用于像button这样的其他东西。

根据您的情况,您可以

cr.commit()  
raise osv.except_osv(_("Warning!"), _("Error"))

但是在商业交易中明确地调用cr.commit会导致严重的问题。

另一种方法是您可以返回带有警告消息的向导。这是大多数人使用的。

return {
            'name': 'Provide your popup window name',
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': [res and res[1] or False],
            'res_model': 'your.popup.model.name',
            'context': "{}",
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'res_id': record_id  or False,##please replace record_id and provide the id of the record to be opened 
        }

答案 1 :(得分:0)

我想到了一种方法......你可以使用一些on_change方法来返回这样的字典:

return {
        'warning': {
              'title':'Message title!',
              'message':'Your message text goes here!'
               }
        }
相关问题