From 0b30c4b86150e055a87dff21285a40c9d06df4ff Mon Sep 17 00:00:00 2001
From: Emmanuel Arias <eamanu@yaerobi.com>
Date: Thu, 9 Jan 2020 19:17:37 -0300
Subject: Test Argentinian CUIT type

The first two digits of the CUIT indicate the type of CUIT (personal,
company or international) and can only have certain values.

Closes https://github.com/arthurdejong/python-stdnum/issues/179
Closes https://github.com/arthurdejong/python-stdnum/pull/181
---
 stdnum/ar/cuit.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

(limited to 'stdnum')

diff --git a/stdnum/ar/cuit.py b/stdnum/ar/cuit.py
index 6325dce..89522b2 100644
--- a/stdnum/ar/cuit.py
+++ b/stdnum/ar/cuit.py
@@ -27,16 +27,12 @@
 The CUIT is a taxpayer identification number used for VAT (IVA, Impuesto al
 Valor Agregado) and other taxes.
 
->>> validate('200-5536168-2')
+More information:
+
+* https://es.wikipedia.org/wiki/Clave_Única_de_Identificación_Tributaria
+
+>>> validate('20-05536168-2')
 '20055361682'
->>> validate('2026756539')
-Traceback (most recent call last):
-    ...
-InvalidLength: ...
->>> validate('2026756A393')
-Traceback (most recent call last):
-    ...
-InvalidFormat: ...
 >>> validate('20267565392')
 Traceback (most recent call last):
     ...
@@ -62,6 +58,14 @@ def calc_check_digit(number):
     return '012345678990'[11 - check]
 
 
+# The different types of CUIT that are known
+_cuit_tpes = (
+    '20', '23', '24', '27',     # individuals
+    '30', '33', '34',           # companies
+    '50', '51', '55',           # international purposes
+)
+
+
 def validate(number):
     """Check if the number is a valid CUIT."""
     number = compact(number)
@@ -69,6 +73,8 @@ def validate(number):
         raise InvalidLength()
     if not isdigits(number):
         raise InvalidFormat()
+    if number[:2] not in _cuit_tpes:
+        raise InvalidComponent()
     if calc_check_digit(number[:-1]) != number[-1]:
         raise InvalidChecksum()
     return number
-- 
cgit v1.2.3