From afdee1335e0c145d50ab53f3d9ca581253e4eb9b Mon Sep 17 00:00:00 2001 From: eduar Date: Thu, 16 Apr 2026 07:00:46 +0200 Subject: [PATCH] carieri label --- config/label_templates/203/LabelCARRIERI.prn | 28 +++++ src/scripts/print_labels_csv.py | 126 +++++++++++++++---- 2 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 config/label_templates/203/LabelCARRIERI.prn diff --git a/config/label_templates/203/LabelCARRIERI.prn b/config/label_templates/203/LabelCARRIERI.prn new file mode 100644 index 0000000..66074a9 --- /dev/null +++ b/config/label_templates/203/LabelCARRIERI.prn @@ -0,0 +1,28 @@ +CT~~CD,~CC^~CT~ +^XA +~TA000 +~JSN +^LT0 +^MNW +^MTT +^PON +^PMN +^LH0,0 +^JMA +^PR2,2 +~SD20 +^JUS +^LRN +^CI27 +^PA0,1,1,0 +^XZ +^XA +^MMT +^PW240 +^LL128 +^LS0 +^FT75,107^BQN,2,2 +^FH\^FDLA,HOSE5803647057|000|0000|B1|YES|YES|Errecinque srl|00001|OCG36006208|
16-16-2026|000000PART|000^FS +^FT20,124^A0N,17,25^FH\^CI28^FD{PART}_C1^FS^CI27 +^PQ1,0,1,Y +^XZ diff --git a/src/scripts/print_labels_csv.py b/src/scripts/print_labels_csv.py index e67f574..d76b83c 100644 --- a/src/scripts/print_labels_csv.py +++ b/src/scripts/print_labels_csv.py @@ -1,4 +1,4 @@ -import csv +import sys import time from datetime import datetime @@ -7,38 +7,87 @@ from PyQt5.QtWidgets import QApplication from src.components.os_label_printer import * from src.lib.helpers import ConfigReader -SYSTEM_ID = "test-linux" -CSV_PATH="tmp/promatec.csv" -TEMPLATE="ferrari_flag_qr_only.prn" -#TEMPLATE="ferrari_30x16_203.prn" +# --- Product Data --- +PRODUCTS = { + "5803647057": {"CN": "pressure-hose_SG", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, + "5803647058": {"CN": "Return-hose-SG", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, + "5803647061": {"CN": "pressure-hose-fn4", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, + "5803648415": {"CN": "NVH-HOSE", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, + "5803688601": {"CN": "NVH-HOSE-xc13-fn4", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, + "5803610921": {"CN": "NVH-HOSE-ESRA", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, + "5803610922": {"CN": "NVH-HOSE-ESRA", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, + "5803610923": {"CN": "NVH-HOSE-ESRA", "RV": "000", "BL": "00001", "SC": "B1", "AC": "YES", "PC": "NO", "LT": "000000PART", "LV": "000"}, +} -config = ConfigReader(system_id=SYSTEM_ID) -printer=Os_Label_Printer(config=config,name="label_printer") +def generate_qr_code(product_pn, product_data, ocg, supplier_name, date_obj, serial_number): + # Format date as day/week_number/year, e.g., 09/15/2026 + date_str = date_obj.strftime("%d/%W/%Y") + qr_string = ( + f"{product_data['CN']}|{product_pn}|{product_data['RV']}|" + f"{product_data['BL']}|{product_data['SC']}|{product_data['AC']}|" + f"{product_data['PC']}|{supplier_name}|{serial_number:05d}|" + f"{ocg}|
{date_str}|{product_data['LT']}|{product_data['LV']}" + ) + return qr_string -# timenow = datetime.now() -app = QApplication(sys.argv) +def main(): + SYSTEM_ID = "st-ten-7" + TEMPLATE = "LabelCARRIERI.prn" + FIXED_OCG = "OCG36006208" + + config = ConfigReader(system_id=SYSTEM_ID) + printer = Os_Label_Printer(config=config, name="label_printer") + + app = QApplication(sys.argv) -with open(CSV_PATH, "r", encoding="utf-8-sig") as f: - reader = csv.DictReader(f) - for row in reader: - START_SN = 1 - STOP_SN = int(row["quantity"]) - PN = row["part_number"] - print(f"PART NUMBER # {PN}") + while True: + print("\n--- New Label Printing Session ---") + print("Available Part Numbers:") + for pn in PRODUCTS.keys(): + print(f"- {pn}") + + selected_pn = "" + while selected_pn not in PRODUCTS: + selected_pn = input("Enter the Part Number to print: ") + if selected_pn not in PRODUCTS: + print("Invalid Part Number. Please choose from the list above.") + + product_info = PRODUCTS[selected_pn] + + supplier_name = input("Enter the supplier name: ") + + while True: + try: + quantity_str = input("Enter the number of labels to print [15]: ") + if not quantity_str: + quantity = 15 + break + quantity = int(quantity_str) + if quantity > 0: + break + else: + print("Please enter a positive number.") + except ValueError: + print("Invalid number.") + + print(f"Printing {quantity} labels for PART NUMBER # {selected_pn}") input("Press Enter to continue...") - for sn in range(START_SN,STOP_SN+2): + + last_label_context = None + for sn in range(1, quantity + 1): timenow = datetime.now() print(f"PRINTING LABEL # {sn}") + + # Pass the incrementing serial number 'sn' to the QR code generator + qr_code = generate_qr_code(selected_pn, product_info, FIXED_OCG, supplier_name, timenow, sn) + + # The context now contains the full QR_CODE string with the correct SN, + # and a separate SN for any human-readable fields on the label. context = { - # RECIPE DATA - "PART": PN, - # SERIAL DEFINITION - "SN": str(sn), - "SN4": f"{sn:0>4}", - "SN5": f"{sn:0>5}", - "SN6": f"{sn:0>6}", - # TIME DEFINITION + "QR_CODE": qr_code, + "PART": selected_pn, + "SN": f"{sn:05d}", "DATETIME": timenow.strftime("%d/%m/%Y %H:%M:%S"), "DATE": timenow.strftime("%d/%m/%Y"), "TIME": timenow.strftime("%H:%M:%S"), @@ -51,6 +100,29 @@ with open(CSV_PATH, "r", encoding="utf-8-sig") as f: "SS": timenow.strftime("%S"), "JJJ": timenow.strftime("%j"), } - printer.print_label(TEMPLATE,context) + printer.print_label(TEMPLATE, context) + last_label_context = context + time.sleep(0.5) - time.sleep(.5) \ No newline at end of file + while True: + action = input("\nReprint last label (r), print another product (a), or exit (e)? ").lower() + if action == 'r': + if last_label_context: + print("Reprinting last label...") + printer.print_label(TEMPLATE, last_label_context) + time.sleep(0.5) + else: + print("No label has been printed in this session to reprint.") + elif action == 'a': + break + elif action == 'e': + print("Exiting.") + return + else: + print("Invalid option. Please enter 'r', 'a', or 'e'.") + + if action == 'a': + continue + +if __name__ == "__main__": + main()