Last active
May 21, 2018 20:21
-
-
Save mrts/cdfb0f00cf0fea3643fa7c55a1e57ad9 to your computer and use it in GitHub Desktop.
Estonian bank invoice reference number calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| See https://www.pangaliit.ee/settlements-and-standards/reference-number-of-the-invoice/check-digit-calculator-of-domestic-account-number | |
| """ | |
| def calculate_reference_number(n): | |
| """ | |
| Calculates Estonian bank invoice reference number. | |
| Argument: | |
| n - a string of numbers, e.g. invoice number or any other identifier chosen by the invoicer. | |
| >>> calculate_reference_number('12131295') | |
| '121312952' | |
| """ | |
| checksum = sum(a * int(b) for a, b in zip((7, 3, 1) * 10, reversed(n))) | |
| checkdigit = int(round(checksum, -1)) - checksum | |
| return n + str(checkdigit) | |
| if __name__ == '__main__': | |
| import doctest | |
| doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment