ralphje / django-internationalflavor

Complementing django-localflavor with fields that are applicable to multiple countries
Other
25 stars 19 forks source link

Russian VAT number validator updated #4

Closed okfish closed 7 years ago

okfish commented 9 years ago

Slightly localized for Russian VAT numbers validator with additional test for checksums etc. Proudly stolen from vatnumber package, exactly fom https://github.com/eostman/vatnumber/blob/master/vatnumber/__init__.py#L389

ralphje commented 9 years ago

Thanks for your pull request!

However, there are some problems with it. Could you try to fix the following points:

Perhaps you could add something like this (preferably with tests and docstring!):

def _get_check_digit(to_check, factors, mod=11):
    return sum(int(to_check[i]) * factors[i] for i in range(len(factors))) % mod

... and then include something like this as a check:

if len(rest) == 10 and not _get_check_digit(rest, [2, 4, 10, 3, 5, 9, 4, 6, 8]) % 10 != int(rest[10]):
    raise ValidationError(self.country_failure % {'country': country})

The Dutch check could then also be updated using this _get_check_digit method.