Calculates and returns the checksum for EAN13-Code. Calculates the checksum for the supplied `value` (if any) or for this barcode's internal ``self.ean`` property.
(self, value: str | None = None)
| 82 | return self.ean |
| 83 | |
| 84 | def calculate_checksum(self, value: str | None = None) -> int: |
| 85 | """Calculates and returns the checksum for EAN13-Code. |
| 86 | |
| 87 | Calculates the checksum for the supplied `value` (if any) or for this barcode's |
| 88 | internal ``self.ean`` property. |
| 89 | """ |
| 90 | |
| 91 | ean_without_checksum = value or self.ean[: self.digits] |
| 92 | |
| 93 | evensum = sum(int(x) for x in ean_without_checksum[-2::-2]) |
| 94 | oddsum = sum(int(x) for x in ean_without_checksum[-1::-2]) |
| 95 | return (10 - ((evensum + oddsum * 3) % 10)) % 10 |
| 96 | |
| 97 | def build(self) -> list[str]: |
| 98 | """Builds the barcode pattern from `self.ean`. |