lists.arthurdejong.org
RSS feed

python-stdnum commit: r157 - python-stdnum/stdnum/eu

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum commit: r157 - python-stdnum/stdnum/eu



Author: arthur
Date: Mon Feb 20 21:40:08 2012
New Revision: 157
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=157&view=revision

Log:
add a stdnum.eu.vat.check_vies() function to do an on-line check of the VAT 
number

Modified:
   python-stdnum/stdnum/eu/vat.py

Modified: python-stdnum/stdnum/eu/vat.py
==============================================================================
--- python-stdnum/stdnum/eu/vat.py      Sun Feb 19 23:24:23 2012        (r156)
+++ python-stdnum/stdnum/eu/vat.py      Mon Feb 20 21:40:08 2012        (r157)
@@ -40,6 +40,12 @@
 
 _country_modules = dict()
 
+vies_wsdl = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'
+"""The WSDL URL of the VAT Information Exchange System (VIES) """
+
+# a cached version of the suds client for VIES
+_vies_client = None
+
 
 def _get_cc_module(cc):
     """Get the VAT number module based on the country code."""
@@ -83,3 +89,18 @@
     return [cc
             for cc in country_codes
             if _get_cc_module(cc).is_valid(number)]
+
+
+def check_vies(number):  # pragma: no cover (no tests for this function)
+    """Queries the online European Commission VAT Information Exchange
+    System (VIES) for validity of the provided number. Note that the
+    service has usage limitations (see the VIES website for details).
+    This returns a dict-like object."""
+    # this function isn't automatically tested because it would require
+    # network access for the tests and unnecessarily load the VIES website
+    global _vies_client
+    if not _vies_client:
+        from suds.client import Client
+        _vies_client = Client(vies_wsdl)
+    number = compact(number)
+    return _vies_client.service.checkVat(number[:2], number[2:])
-- 
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/