Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added supplementary check for CUIT number of ar localflavor

Thanks Kevin Schaul for the initial patch.
  • Loading branch information...
commit d9db1d3373e9bee37258d7f6b50bea80c767a28c 1 parent 1d29823
Claude Paroz authored July 09, 2012
3  django/contrib/localflavor/ar/forms.py
@@ -81,6 +81,7 @@ class ARCUITField(RegexField):
81 81
     default_error_messages = {
82 82
         'invalid': _('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'),
83 83
         'checksum': _("Invalid CUIT."),
  84
+        'legal_type': _('Invalid legal type. Type must be 27, 20, 23 or 30.'),
84 85
     }
85 86
 
86 87
     def __init__(self, max_length=None, min_length=None, *args, **kwargs):
@@ -96,6 +97,8 @@ def clean(self, value):
96 97
         if value in EMPTY_VALUES:
97 98
             return ''
98 99
         value, cd = self._canon(value)
  100
+        if not value[:2] in ['27', '20', '23', '30']:
  101
+            raise ValidationError(self.error_messages['legal_type'])
99 102
         if self._calc_cd(value) != cd:
100 103
             raise ValidationError(self.error_messages['checksum'])
101 104
         return self._format(value, cd)
8  tests/regressiontests/localflavor/ar/tests.py
@@ -81,6 +81,7 @@ def test_ARDNIField(self):
81 81
     def test_ARCUITField(self):
82 82
         error_format = ['Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.']
83 83
         error_invalid = ['Invalid CUIT.']
  84
+        error_legal_type = [u'Invalid legal type. Type must be 27, 20, 23 or 30.']
84 85
         valid = {
85 86
             '20-10123456-9': '20-10123456-9',
86 87
             '20-10123456-9': '20-10123456-9',
@@ -94,8 +95,9 @@ def test_ARCUITField(self):
94 95
             '210123456-9': error_format,
95 96
             '20-10123456': error_format,
96 97
             '20-10123456-': error_format,
97  
-             '20-10123456-5': error_invalid,
98  
-             '27-10345678-1': error_invalid,
99  
-             '27-10345678-1': error_invalid,
  98
+            '20-10123456-5': error_invalid,
  99
+            '27-10345678-1': error_invalid,
  100
+            '27-10345678-1': error_invalid,
  101
+            '11211111110': error_legal_type,
100 102
         }
101 103
         self.assertFieldOutput(ARCUITField, valid, invalid)

0 notes on commit d9db1d3

Please sign in to comment.
Something went wrong with that request. Please try again.