2
votes

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

1 Answers

3
votes

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