Odoo中文网|Odoo实施培训

标题: 自定义popup弹出对话框显示错误信息 [打印本页]

作者: agilit_ch    时间: 2016-1-16 10:20
标题: 自定义popup弹出对话框显示错误信息
本帖最后由 agilit_ch 于 2016-1-15 21:28 编辑

在accounting模块的customer invoice(客户发票)中,添加了customer_invoice_number发票号码, 此字段必须是唯一的对于给定的客户,如果用户输入的发票号码在数据库中已经存在,我希望弹出一个对话框(popup)来告诉用户他输入的发票号码重复。
解决方法有两个:
1.   通过给customer_invoice_number 定义sql_constraint为unique,当输入重复时,openerp会自动抛出 Exception(异常), 但这种方法回中断work flow,系统回滚到transaction之前的状态
2.   定义osv.osv_memory类,如unique_warning,该类中有对话框相应的信息和方法warning,如title,message等。 生成wizard的同时用xml来定义对话框显示的内容,  当用户输入发票号码后保存时,检查输入的号码是否已存在,如果是,在write或create方法(override)中用self.pool.get('unique_warning').warning(),    warning方法负责生成对话框对象并将此对象于xml(ir.ui.view)关联

以上是algorithme,代码等待下周上班再来实现。愿于对openerp感兴趣的交流体会cheng.qiang@hotmail.com

作者: agilit_ch    时间: 2016-1-31 04:56
本帖最后由 agilit_ch 于 2016-1-30 15:57 编辑

自己顶一下:
第三种方法: 在addons/warning/warning.py   onchange_invoice_number():
result={}
.........
if invoice number existe:
warning = {
                'title': 'Duplicate of Supplier invoice number' ,
                'message': 'There is already supplier invoice number with ****!'
                }
return result
运行后输入重复发票号码,会弹出带信息的对话框





欢迎光临 Odoo中文网|Odoo实施培训 (http://www.chinaodoo.net/) Powered by Discuz! X3.2