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

def check_views_and_action(cr):
    env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
    
    print("\n=== VERIFICANDO ACCIÓN DE lims.test ===\n")
    
    # Verificar la acción
    action = env.ref('lims_management.action_lims_test', raise_if_not_found=False)
    if action:
        print(f"ID de la acción: {action.id}")
        print(f"Nombre de la acción: {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"Contexto: {action.context}")
        
        # Verificar las vistas disponibles
        print("\n=== VISTAS DE lims.test ===\n")
        
        views = env['ir.ui.view'].search([('model', '=', 'lims.test')])
        for view in views:
            print(f"- {view.name} (tipo: {view.type}, XML ID: {view.xml_id})")
        
        # Simular la apertura de la acción
        print("\n=== SIMULANDO APERTURA DE LA ACCIÓN ===\n")
        
        try:
            # Intentar obtener las vistas que usaría la acción
            model = env['lims.test']
            for view_mode in action.view_mode.split(','):
                view_mode = view_mode.strip()
                print(f"\nIntentando obtener vista '{view_mode}':")
                try:
                    view_id, view_type = model.get_view(view_type=view_mode)
                    actual_view = env['ir.ui.view'].browse(view_id)
                    print(f"  ✓ Vista encontrada: {actual_view.name} (ID: {view_id})")
                except Exception as e:
                    print(f"  ✗ Error: {e}")
        except Exception as e:
            print(f"Error general: {e}")
    else:
        print("✗ No se encontró la acción 'lims_management.action_lims_test'")

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