Code

patch by mbeach for UPC-A checksum
authorAlvin Penner <penner@vaxxine.com>
Sun, 20 Dec 2009 22:09:40 +0000 (17:09 -0500)
committerAlvin Penner <penner@vaxxine.com>
Sun, 20 Dec 2009 22:09:40 +0000 (17:09 -0500)
share/extensions/Barcode/EAN13.py
share/extensions/Barcode/UPCA.py
share/extensions/Barcode/UPCE.py

index 3450893fc19cf5a25b2809f81f21d8bc6fc456b3..c79b7749d68840869b906addafbf21a0418cfc3a 100644 (file)
@@ -42,8 +42,8 @@ class Object(Barcode):
                if len(number) == 12:
                        number = number + self.getChecksum(number)
                else:
-                       if not self.varifyChecksum(number):
-                               sys.stderr.write("EAN13 Checksum not correct for this barcode, omit last charicter to generate new checksum.\n")
+                       if not self.verifyChecksum(number):
+                               sys.stderr.write("EAN13 Checksum not correct for this barcode, omit last character to generate new checksum.\n")
                                return
 
                result = result + guardBar
@@ -83,9 +83,9 @@ class Object(Barcode):
 
                return str(z)
 
-       def varifyChecksum(self, number):
-               new = self.getChecksum(number[:12])
-               existing = number[12]
+       def verifyChecksum(self, number):
+               new = self.getChecksum(number[:-1])
+               existing = number[-1]
                return new == existing
 
        def getStyle(self, index):
index b67d0830b5d28ead0a1d568ed1f3a2550d6a9b09..89c97eed6e478916cc4cb935902d2761c4217e77 100644 (file)
@@ -33,8 +33,8 @@ class Object(EAN13.Object):
                if len(number) == 11:
                        number = number + self.getChecksum(number)
                else:
-                       if not self.varifyChecksum(number):
-                               sys.stderr.write("EAN13 Checksum not correct for this barcode, omit last charicter to generate new checksum.\n")
+                       if not self.verifyChecksum(number):
+                               sys.stderr.write("UPC-A Checksum not correct for this barcode, omit last character to generate new checksum.\n")
                                return
 
                result = result + guardBar
index 0ad51868041dee20d6154b398626977f1f1205e7..b41e94e8c9d3019146f5099d68e18cbe687a3494 100644 (file)
@@ -47,8 +47,8 @@ class Object(EAN13.Object):
                if not echeck:
                        echeck = self.getChecksum(number)
                else:
-                       if not self.varifyChecksum(number + echeck):
-                               sys.stderr.write("UPC-E Checksum not correct for this barcode, omit last charicter to generate new checksum.\n")
+                       if not self.verifyChecksum(number + echeck):
+                               sys.stderr.write("UPC-E Checksum not correct for this barcode, omit last character to generate new checksum.\n")
                                return
 
                number = self.ConvertAtoE(number)