#!/usr/bin/env python3
"""Test render pallet label with real data."""

import sys
sys.path.insert(0, '/home/frappe/erpnext-bench/apps/frappe')
import frappe

frappe.init(site='erpnext.local', sites_path='/home/frappe/erpnext-bench/sites')
frappe.connect()
frappe.set_user('Administrator')

# Get a real pallet
pallet = frappe.get_doc("Pallet", {"pallet_number": ("is", "set")}, limit=1)
if not pallet:
    print("No pallets found")
    frappe.destroy()
    exit(1)

print(f"Testing with Pallet: {pallet.pallet_number} (name: {pallet.name})")

# Get the print format
pf = frappe.get_doc("Print Format", "Pallet Label 4x6")
print(f"Print Format found: {pf.name}")
print(f"  DocType: {pf.doc_type}")
print(f"  Custom: {pf.custom_format}")
print(f"  HTML length: {len(pf.html) if pf.html else 0} chars")

# Try rendering via get_print
from frappe import get_print
html = get_print("Pallet", pallet.name, print_format="Pallet Label 4x6")

# Write to file for inspection
with open("/tmp/pallet_label_test.html", "w") as f:
    f.write(html)

print(f"✓ Rendered to /tmp/pallet_label_test.html")
print(f"  Output length: {len(html)} chars")

frappe.destroy()
