Skip to content

Commit

Permalink
Fix FRNationalIdentificationNumber for corsican people born after 2000
Browse files Browse the repository at this point in the history
Update changelog
  • Loading branch information
leo-naeka committed Aug 22, 2016
1 parent 22be220 commit 4f2ded0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ Modifications to existing flavors:
(`gh-195 <https://github.com/django/django-localflavor/pull/195>`_).
- Allow passing field name as first positional argument of IBANField.
(`gh-236 <https://github.com/django/django-localflavor/pull/236>`_).

- Fixed French FRNationalIdentificationNumber bug with imaginary birth month values.
(`gh-242` <https://github.com/django/django-localflavor/pull/242>`_).
- Fixed French FRNationalIdentificationNumber bug with corsican people born after 2000.
(`gh-242` <https://github.com/django/django-localflavor/pull/242>`_).

1.3 (2016-05-06)
------------------
Expand Down
6 changes: 5 additions & 1 deletion localflavor/fr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -158,14 +159,17 @@ 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'])

# 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
Expand Down
4 changes: 4 additions & 0 deletions tests/test_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4f2ded0

Please sign in to comment.