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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions barcode/ean.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def calculate_checksum(self):
def sum_(x, y):
return int(x) + int(y)

evensum = reduce(sum_, self.ean[-2::-2])
oddsum = reduce(sum_, self.ean[-1::-2])
return (10 - ((evensum + oddsum * 3) % 10)) % 10
evensum = reduce(sum_, self.ean[1:12:2])
oddsum = reduce(sum_, self.ean[0:11:2])
Comment on lines +93 to +94
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 - ((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?


def build(self):
"""Builds the barcode pattern from `self.ean`.
Expand Down