Skip to content

Commit d9db1d3

Browse files
committed
Added supplementary check for CUIT number of ar localflavor
Thanks Kevin Schaul for the initial patch.
1 parent 1d29823 commit d9db1d3

File tree

2 files changed

+8
-3
lines changed
  • django/contrib/localflavor/ar
  • tests/regressiontests/localflavor/ar

2 files changed

+8
-3
lines changed

django/contrib/localflavor/ar/forms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ARCUITField(RegexField):
8181
default_error_messages = {
8282
'invalid': _('Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.'),
8383
'checksum': _("Invalid CUIT."),
84+
'legal_type': _('Invalid legal type. Type must be 27, 20, 23 or 30.'),
8485
}
8586

8687
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
@@ -96,6 +97,8 @@ def clean(self, value):
9697
if value in EMPTY_VALUES:
9798
return ''
9899
value, cd = self._canon(value)
100+
if not value[:2] in ['27', '20', '23', '30']:
101+
raise ValidationError(self.error_messages['legal_type'])
99102
if self._calc_cd(value) != cd:
100103
raise ValidationError(self.error_messages['checksum'])
101104
return self._format(value, cd)

tests/regressiontests/localflavor/ar/tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def test_ARDNIField(self):
8181
def test_ARCUITField(self):
8282
error_format = ['Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.']
8383
error_invalid = ['Invalid CUIT.']
84+
error_legal_type = [u'Invalid legal type. Type must be 27, 20, 23 or 30.']
8485
valid = {
8586
'20-10123456-9': '20-10123456-9',
8687
'20-10123456-9': '20-10123456-9',
@@ -94,8 +95,9 @@ def test_ARCUITField(self):
9495
'210123456-9': error_format,
9596
'20-10123456': error_format,
9697
'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,
100102
}
101103
self.assertFieldOutput(ARCUITField, valid, invalid)

0 commit comments

Comments
 (0)