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

fix checksum issue from #196 #197

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

zspherez
Copy link

As discussed in #196, there is an issue with the generation of checksums for 13 digit EAN's.

>>> EAN13("842169142322")
evens_old 221628
evens_new 419432
evens_old_sum 21
evens_new_sum 23
odds_old 234914
odds_new 826122
odds_old_sum 23
odds_new_sum 21
old_return 4
new_return 0
<EuropeanArticleNumber13('8421691423220')>
>>> ean = EAN13("842169142322")
evens_old 221628
evens_new 419432
evens_old_sum 21
evens_new_sum 23
odds_old 234914
odds_new 826122
odds_old_sum 23
odds_new_sum 21
old_return 4
new_return 0
>>> ean.calculate_checksum()
evens_old 234914
evens_new 419432
evens_old_sum 23
evens_new_sum 23
odds_old 0221628
odds_new 826122
odds_old_sum 21
odds_new_sum 21
old_return 4
new_return 0
0

As seen in the except above, the PR here fixes this issue.

Comment on lines +93 to +94
evensum = reduce(sum_, self.ean[1:12:2])
oddsum = reduce(sum_, self.ean[0:11:2])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break some subclasses like EuropeanArticleNumber8. You should use self.digits instead of 12 here.

return (10 - ((evensum + oddsum * 3) % 10)) % 10
evensum = reduce(sum_, self.ean[1:12:2])
oddsum = reduce(sum_, self.ean[0:11:2])
return (10 - ((oddsum + evensum * 3) % 10)) % 10
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you swap the order here? The result should be the same, right?

@WhyNotHugo
Copy link
Owner

I think that this issue was fixed in #213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants