From 2b6be2ba49d36fea3bed074916b29956fb34492b Mon Sep 17 00:00:00 2001 From: Quality App Developer Date: Sun, 15 Feb 2026 13:19:19 +0200 Subject: [PATCH] Fix QZ Tray library loading and add pairing keys API endpoint - Fix QZ Tray library loading errors (net::ERR_NAME_NOT_RESOLVED) by switching from CDN to local static file - Add /labels/api/pairing-keys endpoint to fetch valid printer pairing keys - Update print_labels.html to use local js/qz-tray.js - Update print_lost_labels.html to use local js/qz-tray.js - Update print_lost_labels_new.html to use correct path js/qz-tray.js - Update fg_scan.html to use local js/qz-tray.js - API returns active pairing keys from qz_pairing_keys table for printer selection --- app/modules/labels/routes.py | 35 +++++++++++++++++++ .../modules/labels/print_labels.html | 5 ++- .../modules/labels/print_lost_labels.html | 2 +- .../modules/labels/print_lost_labels_new.html | 2 +- app/templates/modules/quality/fg_scan.html | 2 +- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/modules/labels/routes.py b/app/modules/labels/routes.py index fb79dd0..e761ea1 100755 --- a/app/modules/labels/routes.py +++ b/app/modules/labels/routes.py @@ -487,4 +487,39 @@ def api_generate_batch_pdf(order_id): except Exception as e: logger.error(f"Error generating batch PDF: {e}") + return jsonify({'error': str(e)}), 500 + + +@labels_bp.route('/api/pairing-keys', methods=['GET'], endpoint='api_pairing_keys') +def api_pairing_keys(): + """Get QZ Tray pairing keys for printer selection""" + if 'user_id' not in session: + return jsonify({'error': 'Unauthorized'}), 401 + + try: + conn = get_db() + cursor = conn.cursor() + + cursor.execute(""" + SELECT id, printer_name, pairing_key, valid_until + FROM qz_pairing_keys + WHERE valid_until >= CURDATE() + ORDER BY printer_name ASC + """) + + pairing_keys = [] + for row in cursor.fetchall(): + pairing_keys.append({ + 'id': row[0], + 'printer_name': row[1], + 'pairing_key': row[2] + }) + + cursor.close() + + logger.info(f"Retrieved {len(pairing_keys)} valid pairing keys") + return jsonify(pairing_keys), 200 + + except Exception as e: + logger.error(f"Error fetching pairing keys: {e}") return jsonify({'error': str(e)}), 500 \ No newline at end of file diff --git a/app/templates/modules/labels/print_labels.html b/app/templates/modules/labels/print_labels.html index 5be448e..dcf538e 100755 --- a/app/templates/modules/labels/print_labels.html +++ b/app/templates/modules/labels/print_labels.html @@ -290,8 +290,11 @@ + + + +--> - + - + + {% endblock %} {% block content %}