/** * Console Test Script for Bluetooth Receipt Printing * * Run this in the browser console while in POS to test receipt printing * * Usage: * 1. Open POS on Android device * 2. Open Chrome DevTools console (chrome://inspect on desktop, connect to device) * 3. Copy and paste this entire script into console * 4. Run: testBluetoothPrint() */ async function testBluetoothPrint() { console.log('=== Bluetooth Print Test Started ==='); // Check if we're in POS if (!window.odoo || !window.odoo.__DEBUG__ || !window.odoo.__DEBUG__.services) { console.error('❌ Not in POS context. Please open this in POS.'); return; } // Get POS service const services = window.odoo.__DEBUG__.services; console.log('✓ Services available:', Object.keys(services)); const pos = services['pos.session'] || services['pos']; if (!pos) { console.error('❌ POS service not found'); console.log('Available services:', Object.keys(services)); return; } console.log('✓ POS service found'); // Check bluetooth config console.log('POS config:', pos.config); console.log('Bluetooth enabled:', pos.config?.bluetooth_printer_enabled); // Check Web Bluetooth API if (!navigator.bluetooth) { console.error('❌ Web Bluetooth API not available'); return; } console.log('✓ Web Bluetooth API available'); // Check for order let order = null; if (typeof pos.get_order === 'function') { order = pos.get_order(); console.log('✓ Got order via get_order()'); } else if (pos.selectedOrder) { order = pos.selectedOrder; console.log('✓ Got order via selectedOrder'); } else if (pos.orders && pos.orders.length > 0) { order = pos.orders[pos.orders.length - 1]; console.log('✓ Got order via orders array'); } if (!order) { console.error('❌ No active order found'); console.log('POS keys:', Object.keys(pos)); return; } console.log('✓ Order found:', order); console.log('Order keys:', Object.keys(order)); console.log('Order name:', order.name || order.pos_reference); // Check order lines let lines = []; if (typeof order.get_orderlines === 'function') { lines = order.get_orderlines(); console.log('✓ Got lines via get_orderlines()'); } else if (order.lines) { lines = order.lines; console.log('✓ Got lines via lines property'); } else if (order.orderlines) { lines = order.orderlines; console.log('✓ Got lines via orderlines property'); } console.log(`✓ Found ${lines.length} order lines`); if (lines.length > 0) { const firstLine = lines[0]; console.log('First line keys:', Object.keys(firstLine)); console.log('First line:', firstLine); } // Check payment lines let payments = []; if (typeof order.get_paymentlines === 'function') { payments = order.get_paymentlines(); console.log('✓ Got payments via get_paymentlines()'); } else if (order.paymentlines) { payments = order.paymentlines; console.log('✓ Got payments via paymentlines property'); } console.log(`✓ Found ${payments.length} payment lines`); // Check company info console.log('Company:', pos.company); // Check cashier let cashier = null; if (typeof pos.get_cashier === 'function') { cashier = pos.get_cashier(); console.log('✓ Got cashier via get_cashier()'); } else if (pos.cashier) { cashier = pos.cashier; console.log('✓ Got cashier via cashier property'); } else if (pos.user) { cashier = pos.user; console.log('✓ Got cashier via user property'); } console.log('Cashier:', cashier); console.log('=== Test Complete ==='); console.log('All data structures look good! Receipt printing should work.'); } // Also provide a function to check bluetooth connection async function checkBluetoothConnection() { console.log('=== Bluetooth Connection Check ==='); if (!navigator.bluetooth) { console.error('❌ Web Bluetooth API not available'); return; } console.log('✓ Web Bluetooth API available'); try { const devices = await navigator.bluetooth.getDevices(); console.log(`✓ Found ${devices.length} paired devices`); devices.forEach((device, index) => { console.log(` ${index + 1}. ${device.name} (${device.id})`); console.log(` Connected: ${device.gatt?.connected || false}`); }); } catch (error) { console.error('❌ Error getting devices:', error); } console.log('=== Check Complete ==='); } // Provide instructions console.log(` ╔════════════════════════════════════════════════════════════╗ ║ Bluetooth Receipt Print Test Script Loaded ║ ╚════════════════════════════════════════════════════════════╝ Available commands: 1. testBluetoothPrint() - Tests if all POS data is accessible - Shows order structure and available methods - Run this AFTER creating an order in POS 2. checkBluetoothConnection() - Checks Web Bluetooth API availability - Lists paired bluetooth devices - Shows connection status Example usage: > testBluetoothPrint() > checkBluetoothConnection() `);