Skip to content

Instantly share code, notes, and snippets.

@mrts
Last active May 21, 2018 20:21
Show Gist options
  • Select an option

  • Save mrts/cdfb0f00cf0fea3643fa7c55a1e57ad9 to your computer and use it in GitHub Desktop.

Select an option

Save mrts/cdfb0f00cf0fea3643fa7c55a1e57ad9 to your computer and use it in GitHub Desktop.
Estonian bank invoice reference number calculator
"""
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