Skip to content

Commit

Permalink
Fix inconsistent checksum calculation for EAN14
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Sep 21, 2023
1 parent 65ba1b5 commit f242961
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions barcode/ean.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,19 @@ class EuropeanArticleNumber14(EuropeanArticleNumber13):
name = "EAN-14"
digits = 13

def calculate_checksum(self):
def calculate_checksum(self) -> int:
"""Calculates the checksum for EAN13-Code.
:returns: The checksum for `self.ean`.
:rtype: Integer
:returns: The checksum for ``self.ean``.
"""

def sum_(x, y):
return int(x) + int(y)

evensum = reduce(sum_, self.ean[::2])
oddsum = reduce(sum_, self.ean[1::2])
ean_without_checksum = self.ean[: self.digits]

evensum = reduce(sum_, ean_without_checksum[::2])
oddsum = reduce(sum_, ean_without_checksum[1::2])
return (10 - (((evensum * 3) + oddsum) % 10)) % 10


Expand Down

0 comments on commit f242961

Please sign in to comment.