Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update weights && add description function
  • Loading branch information
TheDrunkenBear authored and nandgator committed Mar 28, 2025
commit 1462c7bb1b064b33d8b1c23dca99ef635baa4739
31 changes: 25 additions & 6 deletions src/validators/inn.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
"""Inn."""

from .utils import validator
# from .utils import validator


@validator
def inn(value: str):
"""Description"""
# @validator
def inn(value: str, /):
"""Return whether or not given value is a valid russian individual tax number.

Examples:
>>> inn('7736050003')
# Output: True
>>> inn('781100086042')
# Output: True

Args:
value:
Individual tax number string to validate

Returns:
(Literal[True]): If `value` is a valid russian individual tax number.
(ValidationError): If `value` is an invalid russian individual tax number.

Returns:

"""
if not value:
return False

Expand All @@ -18,10 +36,11 @@ def inn(value: str):
return (control_number % 10) == digits[-1] if control_number > 9 else control_number == digits[-1]
# person
elif len(digits) == 12:
weight_coefs1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 6, 0, 0]
weight_coefs1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0, 0]
control_number1 = sum([d * w for d, w in zip(digits, weight_coefs1)]) % 11
weight_coefs2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 0, 0, 0]
weight_coefs2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0]
control_number2 = sum([d * w for d, w in zip(digits, weight_coefs2)]) % 11
print(control_number1, control_number2, value)
return ((control_number1 % 10) == digits[-2] if control_number1 > 9 else control_number1 == digits[-2] and
(control_number2 % 10) == digits[-1] if control_number2 > 9 else control_number2 == digits[-1])
else:
Expand Down