Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Openerp 打开显示消息对话框_Openerp - Fatal编程技术网

Openerp 打开显示消息对话框

Openerp 打开显示消息对话框,openerp,Openerp,如何在openerp中显示消息框?我是这样使用加薪的: raise osv.except_osv(_("Warning!"), _("Error")) return { 'warning': { 'title':'Message title!', 'message':'Your message text goes here!' } } 但这会停止执行其他代码,我只想显示一个信

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

raise osv.except_osv(_("Warning!"), _("Error"))
return {
        'warning': {
              'title':'Message title!',
              'message':'Your message text goes here!'
               }
        }

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

我想到了一种方法。。。您可以使用一些
on_change
方法返回dict,如下所示:

raise osv.except_osv(_("Warning!"), _("Error"))
return {
        'warning': {
              'title':'Message title!',
              'message':'Your message text goes here!'
               }
        }

提出一个
osv。除了_osv
之外,它可以做以下几件事:

1) 中断当前处理(毕竟这是python异常)

2) 使OpenERP回滚当前数据库事务

3) 使OpenERP向用户显示一个对话框,而不是转储堆栈跟踪并向用户发出“坏东西发生了”消息

只要换一次,我们就可以回来

warning = {
        'title': 'Warning!',
        'message' : 'Your message.'
    }
return {'warning': warning}
但它不适用于其他东西,如按钮

对于你的情况,你可以这样做

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 
        }

这需要用户实际更改某些内容,我也可以使用_约束触发它,但这也需要更改某些内容。例如,我需要它通过打开一个客户来显示消息。然后我建议您在模型中添加一些虚拟字段(布尔或字符)(例如,我们称之为“show_message”)。将该字段添加到_defaults={'show_message':True}并将_change方法绑定到该字段。这样,当用户打开表单视图时,on_change方法将运行,并显示您的消息。这将不起作用,因为on_change要求用户更改该特定字段。按代码操作不会触发on_更改您是否需要为常规osv.osv模型或向导执行此操作?对于常规osv.osv模型,如果不想破坏代码,您需要依靠向导弹出警告。