How can I raise a warning message in Odoo website

青春壹個敷衍的年華 提交于 2020-01-01 19:06:12

问题


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.

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?


回答1:


You can use a JSON-RPC call to backend when submit button is clicked, before sending form data.

  1. 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'
    
  2. 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
            })        
        }
    })();
    
  3. Set a form validation JS method like this: http://www.w3schools.com/js/js_validation.asp



来源:https://stackoverflow.com/questions/34069000/how-can-i-raise-a-warning-message-in-odoo-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!