Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwanted behaviour of the no_checksum option for EuropeanArticleNumber13 #43

Closed
mzonzon opened this issue Jul 1, 2019 · 4 comments · Fixed by #224
Closed

Unwanted behaviour of the no_checksum option for EuropeanArticleNumber13 #43

mzonzon opened this issue Jul 1, 2019 · 4 comments · Fixed by #224
Labels

Comments

@mzonzon
Copy link

mzonzon commented Jul 1, 2019

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

@AlexP11223
Copy link

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

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

instead of 1234567891234.

@WhyNotHugo
Copy link
Owner

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

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

@WhyNotHugo WhyNotHugo added the bug label Dec 3, 2020
@AlexP11223
Copy link

AlexP11223 commented Dec 3, 2020

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. 🤔
Just wrong last digit output like above.

@zhusihan-python
Copy link

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

WhyNotHugo added a commit that referenced this issue Apr 8, 2024
The `ean` variable was shadowed early, so a custom 13th digit was lost
when ignoring checksums.

Fixes: #43
WhyNotHugo added a commit that referenced this issue Apr 8, 2024
The `ean` variable was shadowed early, so a custom 13th digit was lost
when ignoring checksums.

Fixes: #43
WhyNotHugo added a commit that referenced this issue Apr 8, 2024
The `ean` variable was shadowed early, so a custom 13th digit was lost
when ignoring checksums.

Fixes: #43
WhyNotHugo added a commit that referenced this issue Apr 8, 2024
The `ean` variable was shadowed early, so a custom 13th digit was lost
when ignoring checksums.

Fixes: #43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants