diff --git a/docs/authors.rst b/docs/authors.rst index ede3e6055..e0bfa930e 100644 --- a/docs/authors.rst +++ b/docs/authors.rst @@ -10,6 +10,7 @@ Authors * Alex Gaynor * Alex Hill * Alex Zhang +* Alexey Kotlyarov * Alix Martineau * Alonisser * Andreas Pelme diff --git a/docs/changelog.rst b/docs/changelog.rst index 7f4182606..ba191a470 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -21,6 +21,8 @@ Modifications to existing flavors: (`gh-277 `_) - Fixed Dutch NLZipCodeField field not to store empty value as a single space. (`gh-280 `_) +- Fixed validation for old Australian tax file numbers. + (`gh-284 `_) Other changes: diff --git a/localflavor/au/validators.py b/localflavor/au/validators.py index ded94c667..47bc1a452 100644 --- a/localflavor/au/validators.py +++ b/localflavor/au/validators.py @@ -56,6 +56,7 @@ class AUTaxFileNumberFieldValidator(RegexValidator): Validation for Australian Tax File Numbers. .. versionadded:: 1.4 + .. versionchanged:: 1.5 """ error_message = _('Enter a valid TFN.') @@ -75,7 +76,12 @@ def _is_valid(self, value): """ # 1. Multiply each digit by its weighting factor. digits = [int(i) for i in list(value)] - weighting_factors = [1, 4, 3, 7, 5, 8, 6, 9, 10] + + if len(digits) == 8: + weighting_factors = [10, 7, 8, 4, 6, 3, 5, 1] + else: + weighting_factors = [1, 4, 3, 7, 5, 8, 6, 9, 10] + weighted = [digit * weight for digit, weight in zip(digits, weighting_factors)] # 2. Sum the resulting values. diff --git a/tests/test_au/tests.py b/tests/test_au/tests.py index 206ba0387..f9522e341 100644 --- a/tests/test_au/tests.py +++ b/tests/test_au/tests.py @@ -233,6 +233,14 @@ def test_raises_error_for_invalid_tfn(self): validator = AUTaxFileNumberFieldValidator() self.assertRaises(ValidationError, lambda: validator(invalid_tfn)) + def test_old_tfn(self): + """Test old, 8-digit TFNs.""" + validator = AUTaxFileNumberFieldValidator() + old_valid_tfn = '38593474' + validator(old_valid_tfn) + old_invalid_tfn = '38593475' + self.assertRaises(ValidationError, lambda: validator(old_invalid_tfn)) + class AULocalFlavorAUBusinessNumberModelTests(TestCase):