From 07c2c5ddd84533acb5331b4bb329e34f8c25b4c7 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 13 Feb 2014 15:12:46 +0100 Subject: [PATCH] [FIX] base_vat: support Irish Tax numbers introduced in 2013 This is a temporary fix until upstream is fixed. References: - http://en.wikipedia.org/wiki/Personal_Public_Service_Number - https://www.welfare.ie/en/Pages/Extension-of-the-Personal-Public-Service-Number-Range.aspx bzr revid: odo@openerp.com-20140213141246-t56sx1t8x4riey4w --- addons/base_vat/base_vat.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/addons/base_vat/base_vat.py b/addons/base_vat/base_vat.py index ab3e6b71e40..374e910e6e6 100644 --- a/addons/base_vat/base_vat.py +++ b/addons/base_vat/base_vat.py @@ -54,7 +54,7 @@ _ref_vat = { 'gr': 'GR12345670', 'hu': 'HU12345676', 'hr': 'HR01234567896', # Croatia, contributed by Milan Tribuson - 'ie': 'IE1234567T', + 'ie': 'IE1234567FA', 'it': 'IT12345670017', 'lt': 'LT123456715', 'lu': 'LU12345613', @@ -190,6 +190,34 @@ class res_partner(osv.osv): return check == int(num[8]) return False + def _ie_check_char(self, vat): + vat = vat.zfill(8) + extra = 0 + if vat[7] not in ' W': + if vat[7].isalpha(): + extra = 9 * (ord(vat[7]) - 64) + else: + # invalid + return -1 + checksum = extra + sum((8-i) * int(x) for i, x in enumerate(vat[:7])) + return 'WABCDEFGHIJKLMNOPQRSTUV'[checksum % 23] + + def check_vat_ie(self, vat): + """ Temporary Ireland VAT validation to support the new format + introduced in January 2013 in Ireland, until upstream is fixed. + TODO: remove when fixed upstream""" + if len(vat) not in (8, 9) or not vat[2:7].isdigit(): + return False + if len(vat) == 8: + # Normalize pre-2013 numbers: final space or 'W' not significant + vat += ' ' + if vat[:7].isdigit(): + return vat[7] == self._ie_check_char(vat[:7] + vat[8]) + elif vat[1] in (string.ascii_uppercase + '+*'): + # Deprecated format + # See http://www.revenue.ie/en/online/third-party-reporting/reporting-payment-details/faqs.html#section3 + return vat[7] == self._ie_check_char(vat[2:7] + vat[0] + vat[8]) + return False # Mexican VAT verification, contributed by # and Panos Christeas