Closed LucasCallista closed 1 year ago
I am looking further into the code on how it calculates the check_digit and nothing seems wrong: when i execute the following the utils method returns 10 but the copied local utils method that is an exact copy in this script returns 0 as intended.
from pyepc import utils
number = "15430000001123459"
print(utils.calculate_check_digit(number))
def local_check_digit(number):
"""
Given a number without the check-digit, calculate
the check digit and return it.
See: https://www.gs1.org/services/how-calculate-check-digit-manually
"""
# Step 2: Multiply alternate position by 3 and 1
# and get the sum
step_2 = sum([int(n) * 3 for n in number[::-1][::2]]) + sum(
[int(n) for n in number[::-1][1::2]]
)
if step_2 % 10 == 0:
return "0"
# Subtract the sum from nearest equal or higher multiple of ten
return str(10 - (step_2 % 10))
print(local_check_digit(number))
10 0
Ah I see pip installs 0.0.3 and not 0.5.0 because of the python version.
Installed on python 3.10.9 and did not encounter any issues
Your environment
Description
I was looking at this package to generate sscc barcodes but noticed that when generating multiple digits some of them where to long. This always happens when the check digit is 0 and i believe it might be setting the check digit to 10 thus making the total barcode 19 long instead of 18. example:
output: