From 11eaf5b4b7ba979d3a3922103fd5424d3118d607 Mon Sep 17 00:00:00 2001 From: Rohan Bansal Date: Fri, 5 Jul 2024 13:23:13 +0530 Subject: [PATCH] fix: format zpl wrapper functions --- beam/beam/barcodes.py | 56 +++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/beam/beam/barcodes.py b/beam/beam/barcodes.py index 4da845a6..8d01dd04 100644 --- a/beam/beam/barcodes.py +++ b/beam/beam/barcodes.py @@ -1,10 +1,11 @@ import base64 import uuid -from io import BytesIO, StringIO +from io import BytesIO -import barcode import frappe -import zebra_zpl +from barcode import Code128 +from barcode.writer import ImageWriter +from zebra_zpl import Barcode, Label, Printable, Text @frappe.whitelist() @@ -38,7 +39,8 @@ 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}, ) @@ -49,7 +51,7 @@ def barcode128(barcode_text: str) -> str: @frappe.whitelist() @frappe.read_only() def formatted_zpl_barcode(barcode_text: str) -> str: - bc = zebra_zpl.Barcode( + bc = Barcode( barcode_text, type="C", human_readable="Y", @@ -59,16 +61,15 @@ def formatted_zpl_barcode(barcode_text: str) -> str: justification="C", position=(20, 40), ) - b = bc.to_zpl() - return b + return bc.to_zpl() @frappe.whitelist() @frappe.read_only() def formatted_zpl_label( - width: str, length: str, dpi: int = 203, print_speed: int = 2, copies: int = 1 + width: int, length: int, dpi: int = 203, print_speed: int = 2, copies: int = 1 ) -> str: - l = frappe._dict({}) + l = frappe._dict() # ^XA Start format # ^LL