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