#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import odoo

def check_views(cr):
    env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
    
    print("\n=== VERIFICANDO VISTAS DE lims.test ===\n")
    
    # Buscar todas las vistas del modelo
    views = env['ir.ui.view'].search([('model', '=', 'lims.test')])
    
    print(f"Total de vistas encontradas: {len(views)}\n")
    
    for view in views:
        print(f"ID: {view.id}")
        print(f"Nombre: {view.name}")
        print(f"Tipo: {view.type}")
        print(f"Prioridad: {view.priority}")
        print(f"Activa: {view.active}")
        print(f"XML ID: {view.xml_id}")
        print("-" * 50)
    
    # Verificar la acción
    print("\n=== VERIFICANDO ACCIÓN ===\n")
    
    action = env.ref('lims_management.action_lims_test', raise_if_not_found=False)
    if action:
        print(f"Acción encontrada: {action.name}")
        print(f"Modelo: {action.res_model}")
        print(f"View mode: {action.view_mode}")
        print(f"View ID: {action.view_id.name if action.view_id else 'No definida'}")
        print(f"Search view ID: {action.search_view_id.name if action.search_view_id else 'No definida'}")
        
        # Verificar las vistas específicas
        print("\nVistas específicas de la acción:")
        for view_ref in action.view_ids:
            print(f"  - Tipo: {view_ref.view_mode}, Vista: {view_ref.view_id.name if view_ref.view_id else 'Por defecto'}")
    else:
        print("⚠️  No se encontró la acción")
    
    # Probar obtener la vista por defecto
    print("\n=== PROBANDO OBTENER VISTA POR DEFECTO ===\n")
    
    try:
        view_id, view_type = env['lims.test'].get_view()
        print(f"Vista por defecto: ID={view_id}, Tipo={view_type}")
        
        # Intentar obtener vista tree específicamente
        tree_view = env['lims.test'].get_view(view_type='tree')
        print(f"Vista tree: ID={tree_view[0]}, Tipo={tree_view[1]}")
    except Exception as e:
        print(f"❌ Error al obtener vista: {e}")

if __name__ == '__main__':
    db_name = 'lims_demo'
    registry = odoo.registry(db_name)
    with registry.cursor() as cr:
        check_views(cr)