
- Agregar campo computed selection_options_display que muestra las opciones disponibles - Implementar método _compute_selection_options_display que obtiene opciones del parámetro - Actualizar vista para mostrar las opciones disponibles debajo del campo de entrada - Remover widget selection que no funciona con campos Char dinámicos - Agregar placeholder descriptivo para guiar al usuario El usuario ahora puede ver las opciones válidas (ej: "Negativo < /dev/null | Positivo") y escribir el valor correcto en el campo de texto. Scripts de prueba agregados para validar la solución. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
151 lines
6.0 KiB
Python
151 lines
6.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Script para analizar el problema con selection_values en lims.test
|
|
Específicamente para test.id: 33 y result.id: 43
|
|
"""
|
|
|
|
import odoo
|
|
import logging
|
|
import json
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
def analyze_selection_issue(env, test_id=33, result_id=43):
|
|
"""Analizar el problema con selection_values"""
|
|
|
|
print("=" * 80)
|
|
print("ANÁLISIS DE PROBLEMA CON SELECTION_VALUES")
|
|
print("=" * 80)
|
|
|
|
# 1. Buscar el test específico
|
|
test = env['lims.test'].browse(test_id)
|
|
if not test.exists():
|
|
print(f"\n❌ No se encontró el test con ID {test_id}")
|
|
return
|
|
|
|
print(f"\n1. INFORMACIÓN DEL TEST:")
|
|
print(f" - ID: {test.id}")
|
|
print(f" - Nombre: {test.name}")
|
|
print(f" - Producto: {test.product_id.name}")
|
|
print(f" - Estado: {test.state}")
|
|
print(f" - Número de resultados: {len(test.result_ids)}")
|
|
|
|
# 2. Buscar el resultado específico
|
|
result = env['lims.result'].browse(result_id)
|
|
if not result.exists():
|
|
print(f"\n❌ No se encontró el resultado con ID {result_id}")
|
|
return
|
|
|
|
print(f"\n2. INFORMACIÓN DEL RESULTADO:")
|
|
print(f" - ID: {result.id}")
|
|
print(f" - Test ID: {result.test_id.id}")
|
|
print(f" - Parámetro: {result.parameter_id.name}")
|
|
print(f" - Tipo de valor: {result.parameter_value_type}")
|
|
print(f" - Valor actual (selection): '{result.value_selection}'")
|
|
|
|
# 3. Analizar el parámetro
|
|
parameter = result.parameter_id
|
|
print(f"\n3. INFORMACIÓN DEL PARÁMETRO:")
|
|
print(f" - ID: {parameter.id}")
|
|
print(f" - Nombre: {parameter.name}")
|
|
print(f" - Código: {parameter.code}")
|
|
print(f" - Tipo de valor: {parameter.value_type}")
|
|
print(f" - Selection values: '{parameter.selection_values}'")
|
|
|
|
# 4. Si es tipo selection, analizar las opciones
|
|
if parameter.value_type == 'selection':
|
|
print(f"\n4. ANÁLISIS DE OPCIONES DE SELECCIÓN:")
|
|
|
|
# Verificar si selection_values está definido
|
|
if parameter.selection_values:
|
|
# Parsear las opciones
|
|
options = [opt.strip() for opt in parameter.selection_values.split(',')]
|
|
print(f" - Opciones disponibles: {options}")
|
|
print(f" - Número de opciones: {len(options)}")
|
|
|
|
# Verificar si el valor actual está en las opciones
|
|
if result.value_selection in options:
|
|
print(f" ✓ El valor actual '{result.value_selection}' está en las opciones")
|
|
else:
|
|
print(f" ✗ El valor actual '{result.value_selection}' NO está en las opciones")
|
|
else:
|
|
print(" ✗ NO hay selection_values definidos en el parámetro")
|
|
|
|
# 5. Buscar todos los resultados con parámetros de tipo selection
|
|
print(f"\n5. ANÁLISIS GLOBAL DE PARÁMETROS TIPO SELECTION:")
|
|
|
|
# Buscar todos los parámetros de tipo selection
|
|
selection_params = env['lims.analysis.parameter'].search([('value_type', '=', 'selection')])
|
|
print(f" - Total de parámetros tipo selection: {len(selection_params)}")
|
|
|
|
for param in selection_params[:5]: # Mostrar primeros 5
|
|
print(f"\n Parámetro: {param.name} (ID: {param.id})")
|
|
print(f" - Selection values: '{param.selection_values}'")
|
|
if param.selection_values:
|
|
options = [opt.strip() for opt in param.selection_values.split(',')]
|
|
print(f" - Opciones: {options}")
|
|
else:
|
|
print(f" - ⚠️ SIN OPCIONES DEFINIDAS")
|
|
|
|
# 6. Verificar cómo se está usando en las vistas
|
|
print(f"\n6. ANÁLISIS DE USO EN VISTAS:")
|
|
print(" - En lims_test_views.xml, el campo value_selection usa widget='selection'")
|
|
print(" - Este widget espera opciones dinámicas que deberían venir del campo related")
|
|
print(" - Pero las opciones no se están propagando correctamente a la vista")
|
|
|
|
# 7. Buscar resultados con value_selection vacío
|
|
empty_selection_results = env['lims.result'].search([
|
|
('parameter_value_type', '=', 'selection'),
|
|
('value_selection', '=', False)
|
|
])
|
|
print(f"\n7. RESULTADOS CON SELECTION VACÍO:")
|
|
print(f" - Total: {len(empty_selection_results)}")
|
|
|
|
# 8. Propuesta de solución
|
|
print(f"\n8. DIAGNÓSTICO Y SOLUCIÓN PROPUESTA:")
|
|
print(" - PROBLEMA: El widget selection en la vista no recibe las opciones dinámicamente")
|
|
print(" - CAUSA: Las opciones están en parameter.selection_values pero no se propagan al widget")
|
|
print(" - SOLUCIÓN 1: Usar un campo Selection con función que obtenga opciones dinámicamente")
|
|
print(" - SOLUCIÓN 2: Cambiar a widget text en la vista para entrada manual")
|
|
print(" - SOLUCIÓN 3: Implementar un widget personalizado que lea selection_values del parámetro")
|
|
|
|
return {
|
|
'test_id': test_id,
|
|
'result_id': result_id,
|
|
'parameter_name': parameter.name,
|
|
'parameter_type': parameter.value_type,
|
|
'selection_values': parameter.selection_values,
|
|
'current_value': result.value_selection,
|
|
'has_options': bool(parameter.selection_values),
|
|
'empty_results_count': len(empty_selection_results)
|
|
}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# Configuración
|
|
db_name = 'lims_demo'
|
|
|
|
# Conectar a Odoo
|
|
odoo.tools.config.parse_config(['--database', db_name])
|
|
|
|
# Obtener el registro de la base de datos
|
|
registry = odoo.registry(db_name)
|
|
|
|
# Crear cursor y environment
|
|
with registry.cursor() as cr:
|
|
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
|
|
|
|
try:
|
|
# Analizar el problema
|
|
analysis = analyze_selection_issue(env)
|
|
|
|
print("\n" + "=" * 80)
|
|
print("RESUMEN DEL ANÁLISIS:")
|
|
print(json.dumps(analysis, indent=2, ensure_ascii=False))
|
|
print("=" * 80)
|
|
|
|
except Exception as e:
|
|
print(f"\n❌ Error durante el análisis: {str(e)}")
|
|
_logger.error(f"Error analizando selection issue: {str(e)}", exc_info=True) |