diff options
| author | Jairo Llopis <yajo.sk8@gmail.com> | 2017-05-30 15:56:10 +0200 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2017-05-31 10:47:51 +0200 |
| commit | bef9b1114c2e8a15e8a87e1eb5f0451f93ec75d3 (patch) | |
| tree | 9c1c803f45ee3956adc67ad235eae386fe2feb4d | |
| parent | 8682c54d060794a63906ce2f399e29cafc42886f (diff) | |
[IMP] website_sale: Allow to validate VAT without country code in checkout step
Closes #17316
If the user already specifies the country and does not give the country vat prefix, use the one from the address to validate the VAT.
| -rw-r--r-- | addons/website_sale/controllers/main.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 4ea4f981320..c43e3353671 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -463,8 +463,9 @@ class WebsiteSale(http.Controller): # Required fields from mandatory field function required_fields += mode[1] == 'shipping' and self._get_mandatory_shipping_fields() or self._get_mandatory_billing_fields() # Check if state required + country = request.env['res.country'] if data.get('country_id'): - country = request.env['res.country'].browse(int(data.get('country_id'))) + country = country.browse(int(data.get('country_id'))) if 'state_code' in country.get_address_fields() and country.state_ids: required_fields += ['state_id'] @@ -484,7 +485,10 @@ class WebsiteSale(http.Controller): check_func = request.website.company_id.vat_check_vies and Partner.vies_vat_check or Partner.simple_vat_check vat_country, vat_number = Partner._split_vat(data.get("vat")) if not check_func(vat_country, vat_number): - error["vat"] = 'error' + if country.code and check_func(country.code, data["vat"]): + data["vat"] = country.code + data["vat"] + else: + error["vat"] = 'error' if [err for err in pycompat.items(error) if err == 'missing']: error_message.append(_('Some required fields are empty.')) |
