Skip to content

Commit f242961

Browse files
committed
Fix inconsistent checksum calculation for EAN14
1 parent 65ba1b5 commit f242961

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

barcode/ean.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,19 @@ class EuropeanArticleNumber14(EuropeanArticleNumber13):
212212
name = "EAN-14"
213213
digits = 13
214214

215-
def calculate_checksum(self):
215+
def calculate_checksum(self) -> int:
216216
"""Calculates the checksum for EAN13-Code.
217217
218-
:returns: The checksum for `self.ean`.
219-
:rtype: Integer
218+
:returns: The checksum for ``self.ean``.
220219
"""
221220

222221
def sum_(x, y):
223222
return int(x) + int(y)
224223

225-
evensum = reduce(sum_, self.ean[::2])
226-
oddsum = reduce(sum_, self.ean[1::2])
224+
ean_without_checksum = self.ean[: self.digits]
225+
226+
evensum = reduce(sum_, ean_without_checksum[::2])
227+
oddsum = reduce(sum_, ean_without_checksum[1::2])
227228
return (10 - (((evensum * 3) + oddsum) % 10)) % 10
228229

229230

0 commit comments

Comments
 (0)