Opened 6 years ago

Closed 3 years ago

#10204 closed Bug (invalid)

Validation fails in spanish localflavor ESIdentityCardNumberField

Reported by: meaksh Owned by: meaksh
Component: contrib.localflavor Version: master
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 meaksh 6 years ago.
regressiontests.diff (813 bytes) - added by meaksh 6 years ago.
Regressions Tests
patch_and_tests_final.diff (2.2 KB) - added by meaksh 6 years ago.
patch and regressiontests in same file.
patch_nifniecif_es.diff (2.2 KB) - added by Cesar Ortiz <cesar.ortiz@…> 6 years ago.
An alternative (and right) patch

Download all attachments as: .zip

Change History (20)

Changed 6 years ago by meaksh

comment:1 Changed 6 years ago by meaksh

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 6 years ago by meaksh

  • Component changed from Uncategorized to django.contrib.localflavor
  • Has patch set

comment:3 Changed 6 years ago by meaksh

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 6 years ago by meaksh

  • Keywords ESIdentityCardNumberField NIE added
  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 6 years ago by russellm

  • Triage Stage changed from Ready for checkin to Accepted

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

Changed 6 years ago by meaksh

Regressions Tests

comment:6 Changed 6 years ago by meaksh

  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 6 years ago by mtredinnick

  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

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 Changed 6 years ago by meaksh

  • Patch needs improvement unset

Changed 6 years ago by meaksh

patch and regressiontests in same file.

comment:9 in reply to: ↑ description Changed 6 years ago by Cesar Ortiz <cesar.ortiz@…>

  • 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 Changed 6 years ago by Cesar Ortiz <cesar.ortiz@…>

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].

Changed 6 years ago by Cesar Ortiz <cesar.ortiz@…>

An alternative (and right) patch

comment:11 Changed 6 years ago by Cesar Ortiz <cesar.ortiz@…>

  • 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 Changed 5 years ago by anonymous

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 Changed 4 years ago by SmileyChris

  • Patch needs improvement set
  • Severity set to Normal
  • Type set to Bug

comment:14 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:15 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:16 Changed 3 years ago by aaugustin

  • Keywords localflavorsplit added
  • Resolution set to invalid
  • Status changed from assigned to closed

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