Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 claudep authored
3  django/contrib/localflavor/ar/forms.py
View
@@ -81,6 +81,7 @@ class ARCUITField(RegexField):
default_error_messages = {
'invalid': _('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'),
'checksum': _("Invalid CUIT."),
+ 'legal_type': _('Invalid legal type. Type must be 27, 20, 23 or 30.'),
}
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
@@ -96,6 +97,8 @@ def clean(self, value):
if value in EMPTY_VALUES:
return ''
value, cd = self._canon(value)
+ if not value[:2] in ['27', '20', '23', '30']:
+ raise ValidationError(self.error_messages['legal_type'])
if self._calc_cd(value) != cd:
raise ValidationError(self.error_messages['checksum'])
return self._format(value, cd)
8 tests/regressiontests/localflavor/ar/tests.py
View
@@ -81,6 +81,7 @@ def test_ARDNIField(self):
def test_ARCUITField(self):
error_format = ['Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.']
error_invalid = ['Invalid CUIT.']
+ error_legal_type = [u'Invalid legal type. Type must be 27, 20, 23 or 30.']
valid = {
'20-10123456-9': '20-10123456-9',
'20-10123456-9': '20-10123456-9',
@@ -94,8 +95,9 @@ def test_ARCUITField(self):
'210123456-9': error_format,
'20-10123456': error_format,
'20-10123456-': error_format,
- '20-10123456-5': error_invalid,
- '27-10345678-1': error_invalid,
- '27-10345678-1': error_invalid,
+ '20-10123456-5': error_invalid,
+ '27-10345678-1': error_invalid,
+ '27-10345678-1': error_invalid,
+ '11211111110': error_legal_type,
}
self.assertFieldOutput(ARCUITField, valid, invalid)
Please sign in to comment.
Something went wrong with that request. Please try again.