Opened 15 years ago

Closed 11 years ago

#10204 closed Bug (invalid)

Validation fails in spanish localflavor ESIdentityCardNumberField

Reported by: Pablo Suárez Hdez. Owned by: Pablo Suárez Hdez.
Component: contrib.localflavor Version: dev
Severity: Normal Keywords: ESIdentityCardNumberField, NIE, localflavorsplit
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

The spanish localflavor ESIdentityCardNumberField accepts the syntax of the spanish official cards type, but due the new revision of the law (http://www.boe.es/boe/dias/2008/07/15/pdfs/A30880-30880.pdf), it need to be updated.

Attachments (4)

spanish_nie.patch (831 bytes ) - added by Pablo Suárez Hdez. 15 years ago.
regressiontests.diff (813 bytes ) - added by Pablo Suárez Hdez. 15 years ago.
Regressions Tests
patch_and_tests_final.diff (2.2 KB ) - added by Pablo Suárez Hdez. 15 years ago.
patch and regressiontests in same file.
patch_nifniecif_es.diff (2.2 KB ) - added by Cesar Ortiz <cesar.ortiz@…> 15 years ago.
An alternative (and right) patch

Download all attachments as: .zip

Change History (20)

by Pablo Suárez Hdez., 15 years ago

Attachment: spanish_nie.patch added

comment:1 by Pablo Suárez Hdez., 15 years ago

Status: newassigned

comment:2 by Pablo Suárez Hdez., 15 years ago

Component: Uncategorizeddjango.contrib.localflavor
Has patch: set

comment:3 by Pablo Suárez Hdez., 15 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Pablo Suárez Hdez., 15 years ago

Keywords: ESIdentityCardNumberField NIE added
Triage Stage: AcceptedReady for checkin

comment:5 by Russell Keith-Magee, 15 years ago

Triage Stage: Ready for checkinAccepted

Not ready for checkin - requires tests (regressiontests/localflavor/es)

by Pablo Suárez Hdez., 15 years ago

Attachment: regressiontests.diff added

Regressions Tests

comment:6 by Pablo Suárez Hdez., 15 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Malcolm Tredinnick, 15 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Please don't mark you own tickets/patches as ready for checkin. As you can see, there are problems that show up in the review and skipping that step isn't a good idea. Just leave the ticket as "accepted" and it will be reviewed in due course.

Please create a single patch containing all the changes so that they can be reviewed in one pass and we don't have to work out which patches need to be applied (particularly if more changes occur before this is applied).

comment:8 by Pablo Suárez Hdez., 15 years ago

Patch needs improvement: unset

by Pablo Suárez Hdez., 15 years ago

Attachment: patch_and_tests_final.diff added

patch and regressiontests in same file.

in reply to:  description comment:9 by Cesar Ortiz <cesar.ortiz@…>, 15 years ago

Patch needs improvement: set

The 'T' letter is not a valid cif/nif.
References:
http://es.wikipedia.org/wiki/NIF
http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
http://es.wikipedia.org/wiki/NIE

Furthemore... to support the XYZ the algorithm must be changed. An '0' (for X), '1' (for the Y), '2' (for Z) should be added at the beggining of the number before the casting to int.

Replying to meaksh:

The spanish localflavor ESIdentityCardNumberField accepts the syntax of the spanish official cards type, but due the new revision of the law (http://www.boe.es/boe/dias/2008/07/15/pdfs/A30880-30880.pdf), it need to be updated.

comment:10 by Cesar Ortiz <cesar.ortiz@…>, 15 years ago

I've been searching about the 'T'...
It looks that is used (or has been used) for foreigners when the number in their country match the format of the spanish number.

"La ley establece que el NIF, en caso de personas físicas extranjeras con documentación del pais de origen podrá sustituirse por el número de identidad válido en su país de origen, precedido por una T. Por tanto y de cara a la validación: TODO NIF QUE COMIENCE POR T ES VÁLIDO, dado que el resto del NIF se rige de acuerdo a la legislación propia de cada país"

But I have not found official documentation.
So, the validation of that number is not possible because the algorithm is not the spanish one. A decision must be taken in order to support T numbers.
Furthemore, the T is treated as an X, what is wrong.

In theory a valid T NIE would be a T followed by 8 characters in the set [A-Z0-9].

by Cesar Ortiz <cesar.ortiz@…>, 15 years ago

Attachment: patch_nifniecif_es.diff added

An alternative (and right) patch

comment:11 by Cesar Ortiz <cesar.ortiz@…>, 15 years ago

Patch needs improvement: unset

I just added another patch.
I included the code to support YZ NIE types and supressed the T as a NIE type.
I don´t think that a NIE T type will appear, is so a new ticket can be opened. I think that the T type should not be consider (anyway the implementation was wrong as a checking should not be done for the T type).

comment:12 by anonymous, 14 years ago

Excuse me but I didn't know how to notify this.
I am using ESIdentityCardNumberField in django 1.2.
cifs starting with "J" should be valid but none passes validation, I get:
'Please enter a valid NIF, NIE, or CIF.'

In fact it surely fails with cifs starting by J,R,U,V,W according to newest normative.
See here: http://www.boe.es/aeboe/consultas/bases_datos/doc.php?id=BOE-A-2008-3580

I suppose it's just a matter of changing:

self.cif_types = 'ABCDEFGHKLMNPQS' to self.cif_types = 'ABCDEFGHJKLMNPQRSUVW'

comment:13 by Chris Beaven, 13 years ago

Patch needs improvement: set
Severity: Normal
Type: Bug

comment:14 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:15 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:16 by Aymeric Augustin, 11 years ago

Keywords: localflavorsplit added
Resolution: invalid
Status: assignedclosed

django.contrib.localflavor is now deprecated — see https://docs.djangoproject.com/en/dev/ref/contrib/localflavor/

A repository was created for each localflavor at https://github.com/django/django-localflavor-? (Replace with the country code.)

If you're still interested in this ticket, could you create a pull request on that repository?

Sorry for not resolving this issue earlier, and thanks for your input!

Note: See TracTickets for help on using tickets.
Back to Top