#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script para listar todas las órdenes de laboratorio
"""

import odoo

def list_orders(cr):
    """Listar todas las órdenes de laboratorio"""
    env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
    
    # Buscar todas las órdenes de laboratorio
    orders = env['sale.order'].search([('is_lab_request', '=', True)], order='name desc')
    
    print(f"📋 Total de órdenes de laboratorio: {len(orders)}\n")
    
    for order in orders:
        print(f"Orden: {order.name}")
        print(f"  Cliente: {order.partner_id.name}")
        print(f"  Estado: {order.state}")
        print(f"  Líneas: {len(order.order_line)}")
        
        # Mostrar análisis
        for line in order.order_line:
            print(f"    - {line.product_id.name}")
        
        # Si tiene prueba de embarazo, mostrar
        has_pregnancy_test = any('embarazo' in line.product_id.name.lower() for line in order.order_line)
        if has_pregnancy_test:
            print("  ⚠️  Incluye prueba de embarazo")
        
        print()

if __name__ == '__main__':
    db_name = 'lims_demo'
    try:
        registry = odoo.modules.registry.Registry(db_name)
        with registry.cursor() as cr:
            list_orders(cr)
    except Exception as e:
        print(f"Error: {e}")