diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 175f3fa3..76f86d78 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -26,7 +26,7 @@ jobs: run: pip install mypy - name: Install mypy types - run: mypy ./beam/. --install-types + run: mypy ./beam/. --install-types --non-interactive - name: Run mypy uses: sasanquaneuf/mypy-github-action@releases/v1 diff --git a/beam/beam/barcodes.py b/beam/beam/barcodes.py index e9a6c93c..8d01dd04 100644 --- a/beam/beam/barcodes.py +++ b/beam/beam/barcodes.py @@ -2,8 +2,10 @@ import uuid from io import BytesIO -import barcode import frappe +from barcode import Code128 +from barcode.writer import ImageWriter +from zebra_zpl import Barcode, Label, Printable, Text @frappe.whitelist() @@ -26,7 +28,7 @@ def create_beam_barcode(doc, method=None): b.idx = row_index + 1 doc.append( "barcodes", - {"barcode": str(uuid.uuid4().int >> 64), "barcode_type": "Code128", "idx": 1}, + {"barcode": f"{str(uuid.uuid4().int >> 64):020}", "barcode_type": "Code128", "idx": 1}, ) return doc @@ -37,9 +39,104 @@ def barcode128(barcode_text: str) -> str: if not barcode_text: return "" temp = BytesIO() - barcode.Code128(barcode_text, writer=barcode.writer.ImageWriter()).write( + instance = Code128(barcode_text, writer=ImageWriter()) + instance.write( temp, options={"module_width": 0.4, "module_height": 10, "font_size": 0, "compress": True}, ) encoded = base64.b64encode(temp.getvalue()).decode("ascii") return f'' + + +@frappe.whitelist() +@frappe.read_only() +def formatted_zpl_barcode(barcode_text: str) -> str: + bc = Barcode( + barcode_text, + type="C", + human_readable="Y", + width=4, + height=260, + ratio=1, + justification="C", + position=(20, 40), + ) + return bc.to_zpl() + + +@frappe.whitelist() +@frappe.read_only() +def formatted_zpl_label( + width: int, length: int, dpi: int = 203, print_speed: int = 2, copies: int = 1 +) -> str: + l = frappe._dict() + # ^XA Start format + # ^LL