django / django-localflavor

Country-specific Django helpers, formerly of contrib fame
https://django-localflavor.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
828 stars 290 forks source link

EAN validator is too picky #331

Closed OdyX closed 6 years ago

OdyX commented 6 years ago

In the context of the https://github.com/defivelo/db project, I have two EAN numbers which validate on https://www.getnewidentity.com/validate-ean.php but are not considered valid by from localflavor.generic.validators.EANValidator:

>>> from localflavor.generic.validators import EANValidator
>>> v = EANValidator()
>>> v('7567554394380')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "…/env/local/lib/python2.7/site-packages/localflavor/generic/validators.py", line 272, in __call__
    raise ValidationError(self.message, code='invalid')
ValidationError: [u'Not a valid EAN code.']
>>> >>> v2("756.4334.3999.00")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "…/env/local/lib/python2.7/site-packages/localflavor/generic/validators.py", line 272, in __call__
    raise ValidationError(self.message, code='invalid')
ValidationError: [u'Not a valid EAN code.']

These don't work for instance:

As mentionned in the pull request, this is an issue about the calculated_checksum which can be 10, which cannot be compared to a single-digit.