我如何在Odoo网站上发出警告消息 [英] How can I raise a warning message in Odoo website
问题描述
在Odoo 8中,我正在使用一个自定义模块,该模块使用@ api.constrains('vat','parent_id','company_id')检查增值税是否是唯一的,并在已经存在增值税的情况下发出警告.
In Odoo 8, I am using a custom module which checks that VAT is unique, using @api.constrains('vat', 'parent_id', 'company_id'), and raising a warning when vat already exists.
但是在网站购买结帐表格中,我是让客户输入增值税.碰巧,当输入重复的增值税时,由于网站没有提供引发警告的方法,我收到500个内部服务器错误.
But in the website purchase checkout form, I am making the customers enter the VAT. It happens that when a repeated VAT is entered I get a 500 internal server error, since the website does not provide a way to raise the warning.
我应该如何实施警告,弹出窗口或类似内容以避免这些内部服务器错误?
How should I implement a warning, a pop-up or similar in order to avoid those internal server errors?
推荐答案
在发送表单数据之前,单击提交按钮时,可以使用JSON-RPC调用后端.
You can use a JSON-RPC call to backend when submit button is clicked, before sending form data.
-
在python中创建新的控制器以验证增值税:
Create a new controller in python for validating a VAT:
@http.route(['/vat/validator'], type='json', auth="public", website=True)
def vat_validator(self, vat):
# Your validation code here
return 'OK'
创建一个用于调用验证程序的JS方法:
Create a JS method for calling validator:
(function() {
'use strict';
function vat_validator(vat) {
openerp.jsonRpc('/vat/validator', 'call', {'vat': vat}).then(function(result) {
// Your JS code here for checking backend validator result
})
}
})();
设置这样的表单验证JS方法: http://www.w3schools. com/js/js_validation.asp
这篇关于我如何在Odoo网站上发出警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!