python-barcode icon indicating copy to clipboard operation
python-barcode copied to clipboard

Unwanted behaviour of the no_checksum option for EuropeanArticleNumber13

Open mzonzon opened this issue 6 years ago • 4 comments

If the no_checksum option is passed, A 13 digits code should be accepted as it is. At the moment, the last digit is replaced by a 0 and it cannot be otherwise:

digits = 12
ean = ean[:self.digits]
# Add a thirteen char if given in parameter,
# otherwise pad with zero
self.ean =  '{0}{1}'.format( ean, ean[self.digits] if len(ean) > self.digits else 0)

len(ean) > self.digits is never going to happen

mzonzon avatar Jul 01 '19 09:07 mzonzon

Bump. Looks like it is indeed does not work as intended.

>>> barcode.get('ean13')('1234567891234', no_checksum=True)
<EuropeanArticleNumber13('1234567891230')>

instead of 1234567891234.

AlexP11223 avatar Dec 03 '20 17:12 AlexP11223

Can you confirm if #98 fixes the issue for you?

If so, I'll add some tests and merge it in. Thanks!

WhyNotHugo avatar Dec 03 '20 19:12 WhyNotHugo

I am too lazy to figure out how to build/install it :D

But yeah, looks correct.

Maybe adding some validation for the number of digits would be good.

Fix crash

hm, I did not have any crashes. :thinking: Just wrong last digit output like above.

AlexP11223 avatar Dec 03 '20 20:12 AlexP11223

hello, is this bug fixed? i tried python-barcode 0.14.0 on windows 10 py 3.9.0, the last digit/checksum can not be disabled

>>> import barcode
>>> barcode.get('ean13')('1234567891234', no_checksum=True)
<EuropeanArticleNumber13('1234567891230')>
>>>
>>> from barcode import EAN13
>>> 
>>> EAN13("1234567891234").get_fullcode()
'1234567891231'
>>>
>>> EAN13("1234567891235").get_fullcode() 
'1234567891231'
>>>
>>> EAN13("1234567891236").get_fullcode()
'1234567891231'
>>>
>>> EAN13("1234567891237").get_fullcode()
'1234567891231'
>>>
>>> EAN13("1234567891237").calculate_checksum()
2

zhusihan-python avatar Jun 16 '22 11:06 zhusihan-python