Files
quality_app-v2/documentation/QUICK_BOX_CHECKPOINT_OLD_VS_NEW.md
Quality App Developer b15cc93b9d FG Scan form validation improvements with warehouse module updates
- Fixed 3 JavaScript syntax errors in fg_scan.html (lines 951, 840-950, 1175-1215)
- Restored form field validation with proper null safety checks
- Re-enabled auto-advance between form fields
- Re-enabled CP code auto-complete with hyphen detection
- Updated validation error messages with clear format specifications and examples
- Added autocomplete='off' to all input fields
- Removed auto-prefix correction feature
- Updated warehouse routes and modules for box assignment workflow
- Added/improved database initialization scripts
- Updated requirements.txt dependencies

Format specifications implemented:
- Operator Code: OP + 2 digits (example: OP01, OP99)
- CP Code: CP + 8 digits + hyphen + 4 digits (example: CP00000000-0001)
- OC1/OC2 Codes: OC + 2 digits (example: OC01, OC99)
- Defect Code: 3 digits only
2026-01-30 10:50:06 +02:00

8.1 KiB
Raw Blame History

Quick Box Checkpoint - Old App vs New App Comparison

Feature Comparison Matrix

Feature Old App New App Status
FG Scan Page Has "Scan To Boxes" toggle Has toggle ✓ Working
Quick Box Creation Button "Quick Box Label Creation" Button exists ⚠️ Non-functional
Auto-Increment Box Numbers BOX00000001, BOX00000002... Missing Need to implement
PDF Label Generation ReportLab PDF with barcode Missing Need to implement
QZ Tray Integration Full implementation ⚠️ Partial Needs completion
Printer Selection Auto-detects default ⚠️ In code but not used Needs implementation
Label Format 8cm × 5cm landscape Not generated Need to implement
Box Assignment Modal Full modal with options Basic modal ⚠️ Incomplete functionality
Database: boxes_crates Creates entry on button click Not created Need backend route
Database: box_contents Links CP to box Not created Need backend route
CP-to-Box Assignment Saves to database Not saved Need backend route
Confirmation Messages Success notifications showNotification exists ✓ Ready to use
Error Handling QZ Tray fallback Not implemented Need implementation
Form Reset Auto-resets after assignment resetForm() exists ✓ Ready to use

Code Location Comparison

Old App (/srv/quality_app/py_app/app/)

Templates

  • FG Scan Frontend: templates/fg_scan.html (1242 lines total)
    • "Scan To Boxes" toggle: Line ~720
    • Quick box button: Line ~875
    • Modal structure: Line ~1119+
    • JavaScript workflow: Line ~880-1100

Routes

  • Box Creation: routes.py (no specific function, inline in FG scan route)
  • PDF Generation: routes.py line ~3700+ (generate_box_label_pdf())
  • QZ Tray Printing: Embedded in template fg_scan.html lines 880-1000

New App (/srv/quality_app-v2/app/modules/quality/)

Templates

  • FG Scan Frontend: templates/modules/quality/fg_scan.html (1005 lines total)
    • "Scan To Boxes" toggle: Line ~50
    • Quick box button: Line ~56
    • Modal structure: Line ~108+
    • JavaScript workflow: Line ~820+ (INCOMPLETE)

Routes

  • No box creation route
  • No PDF generation route
  • No CP assignment route

Detailed Implementation Changes

1. Backend Route Additions Needed

OLD APP:
├─ POST /warehouse/manage_boxes
│  └─ action=add_box → Creates box, returns JSON
├─ POST /generate_box_label_pdf  
│  └─ box_number → Returns PDF blob
└─ FG Scan saves via form submission

NEW APP NEEDS:
├─ POST /quality/api/create-quick-box
│  └─ Returns {success, box_number, box_id}
├─ POST /quality/api/generate-box-label-pdf
│  └─ Returns {success, pdf_base64}
└─ POST /quality/api/assign-cp-to-box
   └─ Returns {success, message}

2. Database Schema

Both apps use same tables:

boxes_crates {
  id, box_number, status, location_id, 
  created_at, updated_at, created_by
}

box_contents {
  id, box_id, cp_code, quantity, created_at
}

But New App:

  • Schema exists
  • Tables created on init
  • Relationships defined
  • Just needs INSERT operations

3. Frontend Differences

Old App Workflow

// lines 880-950
Button click
   Disable button
   POST /warehouse/manage_boxes
   Get box number
   Generate PDF (fetch /generate_box_label_pdf)
   Get PDF blob
   Configure QZ Tray
   Send to printer (await qz.print)
   Show confirmation
   Open modal for scanning
   User scans or enters box
   POST to assign CP
   Reset form

New App Workflow (Current Broken Version)

// line 820-830
Button click
   Check qzTrayReady flag
   Try to call qz.print() directly  WRONG
   No backend calls
   No database updates

Side-by-Side Code Comparison

Box Creation

OLD APP:

# In fg_scan route, after scan recorded:
result = fetch('/warehouse/manage_boxes', {
    method: 'POST',
    body: 'action=add_box'
}).then(r => r.json())
box_number = result.box_number

NEW APP NEEDS:

# New route in quality/routes.py:
@quality_bp.route('/api/create-quick-box', methods=['POST'])
def create_quick_box():
    cursor.execute("""
        INSERT INTO boxes_crates (box_number, status, created_by, created_at)
        VALUES (%s, %s, %s, NOW())
    """, (box_number, 'open', user_id))
    return jsonify({'success': True, 'box_number': box_number})

PDF Generation

OLD APP:

# routes.py line 3727
@bp.route('/generate_box_label_pdf', methods=['POST'])
def generate_box_label_pdf():
    box_number = request.form.get('box_number')
    # ... create PDF with ReportLab
    # ... return PDF blob
    return send_file(pdf_buffer, mimetype='application/pdf')

NEW APP NEEDS:

# New route in quality/routes.py:
@quality_bp.route('/api/generate-box-label-pdf', methods=['POST'])
def generate_box_label_pdf():
    box_number = request.form.get('box_number')
    # ... create PDF with ReportLab
    # ... return base64 (not blob) for QZ Tray
    pdf_base64 = base64.b64encode(pdf_data).decode('utf-8')
    return jsonify({'success': True, 'pdf_base64': pdf_base64})

QZ Tray Configuration

OLD APP:

// Line 950+
const config = qz.configs.create(printer, {
    scaleContent: false,
    rasterize: false,
    size: { width: 80, height: 50 },
    units: 'mm',
    margins: { top: 0, right: 0, bottom: 0, left: 0 }
});

const printData = [{
    type: 'pdf',
    format: 'base64',
    data: pdfBase64
}];

await qz.print(config, printData);

NEW APP (Currently Missing):

// Same code needed in new app
// Currently trying to call qz.print() without config
// Line 825: qz.print({ type: 'label', format: cpCode }) ← WRONG

Missing Requirements in New App

Required from Old App but NOT in New App

  1. PDF Generation Function

    • Old: routes.py lines 3700-3800
    • New: Missing entirely
  2. Box Creation Logic

    • Old: Inline in FG scan route
    • New: No endpoint
  3. Printer Detection

    • Old: qz.printers.find() and getDefault()
    • New: ⚠️ Code exists but not called
  4. QZ Config Creation

    • Old: Proper qz.configs.create() call
    • New: Not called
  5. Base64 PDF Handling

    • Old: PDF blob converted to base64
    • New: Not implemented

Implementation Priority

Critical (Blocking Feature)

  1. Create backend route for box creation
  2. Create backend route for PDF generation
  3. Fix JavaScript workflow

High (Important)

  1. Printer detection and selection
  2. Error handling and fallbacks

Medium (Nice to Have)

  1. Browser print fallback
  2. Advanced logging

Validation Checklist

After implementing, verify:

  • New box created in database (boxes_crates table)
  • Box number auto-increments correctly
  • PDF generates with correct format (8cm × 5cm)
  • Barcode renders in PDF
  • QZ Tray receives PDF
  • Label prints to printer
  • Modal opens after printing
  • CP assignment saved to database
  • box_contents table updated
  • Form resets after completion
  • Error messages show when QZ Tray unavailable
  • Timestamps recorded correctly

Performance Considerations

Operation Old App New App Note
Box creation ~100ms Should be similar Database INSERT
PDF generation ~200-300ms Should be similar ReportLab rendering
Print to QZ ~500-1000ms Should be similar Network + printer
Total workflow ~1-2 seconds Should be similar With good performance

Summary

The new app has the structure ready but needs:

  1. 3 backend routes (copy from old app with adaptations)
  2. JavaScript workflow completion (60+ lines)
  3. Testing (verify each step)

All code patterns already exist in the old app and are documented in the implementation guide.