From 4f2ded0fbe42c2a611c56e6e84db85a432128ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20S?= Date: Thu, 18 Aug 2016 11:48:00 +0200 Subject: [PATCH] Fix FRNationalIdentificationNumber for corsican people born after 2000 Update changelog --- docs/changelog.rst | 5 ++++- localflavor/fr/forms.py | 6 +++++- tests/test_fr.py | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 56af120d3..87fb1e53b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -22,7 +22,10 @@ Modifications to existing flavors: (`gh-195 `_). - Allow passing field name as first positional argument of IBANField. (`gh-236 `_). - +- Fixed French FRNationalIdentificationNumber bug with imaginary birth month values. + (`gh-242` `_). +- Fixed French FRNationalIdentificationNumber bug with corsican people born after 2000. + (`gh-242` `_). 1.3 (2016-05-06) ------------------ diff --git a/localflavor/fr/forms.py b/localflavor/fr/forms.py index ac0f667a3..75a5ceb0b 100644 --- a/localflavor/fr/forms.py +++ b/localflavor/fr/forms.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import re +from datetime import date from django.core.validators import EMPTY_VALUES from django.forms import ValidationError @@ -158,6 +159,9 @@ def clean(self, value): person_unique_number = match.group('person_unique_number') control_key = int(match.group('control_key')) + # Get current year + current_year = int(str(date.today().year)[2:]) + # Department number 98 is for Monaco if department_of_origin == '98': raise ValidationError(self.error_messages['invalid']) @@ -165,7 +169,7 @@ def clean(self, value): # Departments number 20, 2A and 2B represent Corsica if department_of_origin in ['20', '2A', '2B']: # For people born before 1976, Corsica number was 20 - if int(year_of_birth) < 76 and department_of_origin != '20': + if current_year < int(year_of_birth) < 76 and department_of_origin != '20': raise ValidationError(self.error_messages['invalid']) # For people born from 1976, Corsica dep number is either 2A or 2B if (int(year_of_birth) > 75 and diff --git a/tests/test_fr.py b/tests/test_fr.py index 82910d139..c5acad21d 100644 --- a/tests/test_fr.py +++ b/tests/test_fr.py @@ -214,6 +214,10 @@ def test_FRNationalIdentificationNumber(self): '882062A09002279': '882062A09002279', # Good, new Corsica department number (2B) with birthdate >= 1976 '882062B09002279': '882062B09002279', + # Good, new Corsica department number (2B) with birthdate >= 1976 (2005) + '105062B09002231': '105062B09002231', + # Good, new Corsica department number (20) with birthdate < 1976 (1905) + '105062009002231': '105062009002231', # Good, birth month not known (then, can be 20, [30-42] or [50-99]) '140200109002223': '140200109002223', '141330109002285': '141330109002285',