Fix barcode format and improve scannability

- Changed sequential numbering from slash to hyphen format (TEST-ORD-004-0001)
- Increased horizontal barcode bar width from 0.25mm to 0.30mm for better scanning
- Increased vertical barcode bar width from 0.15mm to 0.30mm for reliable readability
- Changed from 3-digit to 4-digit padding for piece numbers (0001 instead of 001)
- Removed aggressive scaling that was distorting barcode bars
- Barcodes now use optimal settings for thermal printers and handheld scanners
This commit is contained in:
Quality App Developer
2026-02-15 17:57:45 +02:00
parent 2b6be2ba49
commit 6029a2b98e
6 changed files with 58 additions and 46 deletions

View File

@@ -87,8 +87,8 @@ class LabelPDFGenerator:
if printer_optimized:
self._optimize_for_label_printer(c)
# Create sequential label number: CP00000711/001, CP00000711/002, etc.
sequential_number = f"{prod_order}/{i:03d}"
# Create sequential label number: CP00000711-0001, CP00000711-0002, etc.
sequential_number = f"{prod_order}-{i:04d}"
# Draw single label
self._draw_label(c, order_data, sequential_number, i, quantity)
@@ -116,7 +116,7 @@ class LabelPDFGenerator:
prod_order = order_data.get('comanda_productie', 'CP00000000')
# Create sequential label number with specific piece number
sequential_number = f"{prod_order}/{piece_number:03d}"
sequential_number = f"{prod_order}-{piece_number:04d}"
print(f"DEBUG: Generating label {sequential_number} (piece {piece_number} of {total_pieces})")
@@ -301,7 +301,7 @@ class LabelPDFGenerator:
canvas.setFont("Helvetica-Bold", 10)
# Match HTML: comanda_productie + "-" + sequential number (not quantity!)
comanda_productie = str(order_data.get('comanda_productie', 'N/A'))
prod_order = f"{comanda_productie}-{current_num:03d}" # Sequential number for this specific label
prod_order = f"{comanda_productie}-{current_num:04d}" # Sequential number for this specific label
po_text_width = canvas.stringWidth(prod_order, "Helvetica-Bold", 10)
po_x_centered = vertical_x + (self.right_column_width - po_text_width) / 2
canvas.drawString(po_x_centered, row_y + self.row_height/3, prod_order)
@@ -321,17 +321,23 @@ class LabelPDFGenerator:
try:
# Create barcode for sequential number
# OPTIMIZED FOR SCANNING: 0.30mm bar width for reliable readability
barcode = code128.Code128(sequential_number,
barWidth=0.25*mm, # Adjust bar width for better fit
barHeight=mm_to_points(10)) # Increase height to 10mm
barWidth=0.30*mm, # Increased from 0.25mm for better scanning
barHeight=mm_to_points(10)) # 10mm height
# Always scale to fit the full allocated width
scale_factor = barcode_width / barcode.width
canvas.saveState()
canvas.translate(barcode_x, barcode_y)
canvas.scale(scale_factor, 1)
barcode.drawOn(canvas, 0, 0)
canvas.restoreState()
# Only scale if barcode is too wide, otherwise use natural size
if barcode.width > barcode_width:
scale_factor = barcode_width / barcode.width
canvas.saveState()
canvas.translate(barcode_x, barcode_y)
canvas.scale(scale_factor, 1)
barcode.drawOn(canvas, 0, 0)
canvas.restoreState()
else:
# Use natural size - center it in available space
x_offset = (barcode_width - barcode.width) / 2
barcode.drawOn(canvas, barcode_x + x_offset, barcode_y)
# NO TEXT BELOW BARCODE - Remove all text rendering for horizontal barcode
@@ -362,18 +368,21 @@ class LabelPDFGenerator:
vertical_code = "000000/00"
# Create a vertical barcode using Code128
# OPTIMIZED FOR SCANNING: 0.30mm bar width for reliable readability
v_barcode = code128.Code128(vertical_code,
barWidth=0.15*mm, # Thinner bars for better fit
barHeight=mm_to_points(8)) # Increased bar height
barWidth=0.30*mm, # Increased from 0.15mm for better scanning
barHeight=mm_to_points(10)) # Increased bar height
# Draw rotated barcode - fill the entire frame height
# Draw rotated barcode - fit naturally without aggressive scaling
canvas.saveState()
canvas.translate(vertical_barcode_x + mm_to_points(6), vertical_barcode_y)
canvas.rotate(90)
# Always scale to fill the frame height
scale_factor = vertical_barcode_height / v_barcode.width
canvas.scale(scale_factor, 1)
# Only scale if barcode is too wide for frame, otherwise use natural size
if v_barcode.width > vertical_barcode_height:
scale_factor = vertical_barcode_height / v_barcode.width
canvas.scale(scale_factor, 1)
# else: use natural size for best scanning quality
v_barcode.drawOn(canvas, 0, 0)
canvas.restoreState()