fix(#67): Solucionar widget selection vacío en resultados
- 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>
This commit is contained in:
parent
ac427ff778
commit
c03afb7f76
26
comment_issue_67.txt
Normal file
26
comment_issue_67.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
## Información adicional tras investigación
|
||||
|
||||
Se confirmó que el método get_selection_list() en lims.analysis.parameter **funciona correctamente**:
|
||||
|
||||
```python
|
||||
# Ejemplo de uso:
|
||||
param = env['lims.analysis.parameter'].browse(36) # Prueba de Embarazo
|
||||
param.selection_values # 'Negativo,Positivo'
|
||||
param.get_selection_list() # ['Negativo', 'Positivo']
|
||||
```
|
||||
|
||||
### El problema real:
|
||||
|
||||
1. **En el modelo lims.result**:
|
||||
- value_selection es un campo Char simple
|
||||
- No hay implementación para obtener las opciones dinámicamente
|
||||
- En la línea 302-304 hay un comentario con pass que indica intención no implementada
|
||||
|
||||
2. **En la vista lims_test_views.xml**:
|
||||
- Usa widget="selection" en un campo Char
|
||||
- El widget espera opciones pero no las recibe
|
||||
|
||||
### Confirmación del bug:
|
||||
- get_selection_list() está disponible y funciona
|
||||
- El problema es que no se está usando para proporcionar opciones al widget
|
||||
- Se necesita implementar la conexión entre el método y la vista
|
48
issue_bug_selection.txt
Normal file
48
issue_bug_selection.txt
Normal file
|
@ -0,0 +1,48 @@
|
|||
## Descripción del problema
|
||||
|
||||
Se detectó un bug en la vista de resultados de pruebas donde el campo value_selection con widget selection aparece vacío y no muestra las opciones disponibles definidas en el parámetro.
|
||||
|
||||
## Detalles técnicos
|
||||
|
||||
### Síntomas:
|
||||
- En lims_test_views.xml, línea 92-93, el campo value_selection usa widget="selection"
|
||||
- El widget aparece vacío sin opciones disponibles
|
||||
- Los valores de selección están definidos en lims.analysis.parameter.selection_values (ej: 'Negativo,Positivo')
|
||||
- El campo no puede recibir valores porque no tiene opciones visibles
|
||||
|
||||
### Caso de ejemplo:
|
||||
- Test ID: 33
|
||||
- Resultado ID: 46
|
||||
- Parámetro: "Prueba de Embarazo"
|
||||
- Opciones en parámetro: 'Negativo,Positivo'
|
||||
- Valor actual en resultado: 'False' (incorrecto)
|
||||
|
||||
### Análisis realizado:
|
||||
Se identificaron 12 parámetros de tipo selection con opciones definidas:
|
||||
- Anticuerpos Hepatitis C: 'No Reactivo,Reactivo,Indeterminado'
|
||||
- Prueba de Embarazo: 'Negativo,Positivo'
|
||||
- Aspecto: 'Transparente,Ligeramente turbio,Turbio,Muy turbio'
|
||||
- Etc.
|
||||
|
||||
## Causa raíz
|
||||
|
||||
El widget selection en Odoo espera un campo de tipo Selection con opciones predefinidas, pero value_selection es un campo Char. Las opciones dinámicas del parámetro (selection_values) no se propagan automáticamente al widget.
|
||||
|
||||
## Impacto
|
||||
|
||||
- Los usuarios no pueden seleccionar valores para resultados de tipo selection
|
||||
- Los datos se guardan incorrectamente (ej: 'False' en lugar de 'Negativo' o 'Positivo')
|
||||
- Afecta la calidad de los datos y la usabilidad del sistema
|
||||
|
||||
## Soluciones propuestas
|
||||
|
||||
1. **Opción 1**: Cambiar el widget a text para permitir entrada manual
|
||||
2. **Opción 2**: Implementar un campo Selection dinámico que obtenga opciones del parámetro
|
||||
3. **Opción 3**: Crear un widget personalizado que lea selection_values del parámetro relacionado
|
||||
|
||||
## Archivos afectados
|
||||
- lims_management/views/lims_test_views.xml (línea 92-93)
|
||||
- lims_management/models/lims_result.py (campo value_selection)
|
||||
|
||||
## Prioridad
|
||||
Media-Alta: Afecta la funcionalidad básica de ingreso de resultados para ciertos tipos de análisis.
|
Binary file not shown.
|
@ -96,6 +96,13 @@ class LimsResult(models.Model):
|
|||
string='Valor de Selección'
|
||||
)
|
||||
|
||||
# Campo para mostrar las opciones disponibles
|
||||
selection_options_display = fields.Char(
|
||||
string='Opciones disponibles',
|
||||
compute='_compute_selection_options_display',
|
||||
help='Opciones válidas para este parámetro'
|
||||
)
|
||||
|
||||
value_boolean = fields.Boolean(
|
||||
string='Valor Sí/No'
|
||||
)
|
||||
|
@ -301,4 +308,17 @@ class LimsResult(models.Model):
|
|||
# Si es selección, obtener las opciones
|
||||
if self.parameter_value_type == 'selection' and self.parameter_id.selection_values:
|
||||
# Esto se usará en las vistas para mostrar las opciones dinámicamente
|
||||
pass
|
||||
pass
|
||||
|
||||
@api.depends('parameter_id', 'parameter_id.selection_values')
|
||||
def _compute_selection_options_display(self):
|
||||
"""Calcula las opciones disponibles para mostrar al usuario."""
|
||||
for record in self:
|
||||
if record.parameter_id and record.parameter_value_type == 'selection':
|
||||
options = record.parameter_id.get_selection_list()
|
||||
if options:
|
||||
record.selection_options_display = ' | '.join(options)
|
||||
else:
|
||||
record.selection_options_display = 'Sin opciones definidas'
|
||||
else:
|
||||
record.selection_options_display = False
|
|
@ -90,8 +90,15 @@
|
|||
class="oe_edit_only"/>
|
||||
<field name="value_selection"
|
||||
invisible="parameter_value_type != 'selection'"
|
||||
widget="selection"
|
||||
placeholder="Seleccione una opción"
|
||||
class="oe_edit_only"/>
|
||||
<field name="selection_options_display"
|
||||
invisible="parameter_value_type != 'selection'"
|
||||
readonly="1"
|
||||
nolabel="1"
|
||||
class="text-muted small"
|
||||
widget="text"
|
||||
style="font-size: 0.85em; color: #6c757d;"/>
|
||||
<field name="value_boolean"
|
||||
invisible="parameter_value_type != 'boolean'"
|
||||
widget="boolean_toggle"
|
||||
|
|
151
test/analyze_selection_bug.py
Normal file
151
test/analyze_selection_bug.py
Normal file
|
@ -0,0 +1,151 @@
|
|||
#!/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)
|
43
test/find_selection_result.py
Normal file
43
test/find_selection_result.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Script para encontrar un resultado real con tipo selection
|
||||
"""
|
||||
|
||||
import odoo
|
||||
|
||||
def find_selection_result(env):
|
||||
"""Buscar un resultado con parámetro tipo selection"""
|
||||
|
||||
# Buscar resultados con parámetros tipo selection
|
||||
results = env['lims.result'].search([
|
||||
('parameter_value_type', '=', 'selection')
|
||||
], limit=5)
|
||||
|
||||
print("RESULTADOS CON PARÁMETROS TIPO SELECTION:")
|
||||
print("=" * 80)
|
||||
|
||||
for result in results:
|
||||
print(f"\nResultado ID: {result.id}")
|
||||
print(f" Test ID: {result.test_id.id}")
|
||||
print(f" Test: {result.test_id.name}")
|
||||
print(f" Parámetro: {result.parameter_id.name}")
|
||||
print(f" Parámetro ID: {result.parameter_id.id}")
|
||||
print(f" Selection values del parámetro: '{result.parameter_id.selection_values}'")
|
||||
print(f" Valor actual: '{result.value_selection}'")
|
||||
|
||||
if result.parameter_id.selection_values:
|
||||
options = [opt.strip() for opt in result.parameter_id.selection_values.split(',')]
|
||||
print(f" Opciones disponibles: {options}")
|
||||
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
db_name = 'lims_demo'
|
||||
odoo.tools.config.parse_config(['--database', db_name])
|
||||
registry = odoo.registry(db_name)
|
||||
|
||||
with registry.cursor() as cr:
|
||||
env = odoo.api.Environment(cr, 1, {})
|
||||
results = find_selection_result(env)
|
78
test/test_get_selection_list.py
Normal file
78
test/test_get_selection_list.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Script para probar que get_selection_list funciona correctamente
|
||||
"""
|
||||
|
||||
import odoo
|
||||
|
||||
def test_get_selection_list(env):
|
||||
"""Probar el método get_selection_list"""
|
||||
|
||||
print("=" * 80)
|
||||
print("PRUEBA DE get_selection_list()")
|
||||
print("=" * 80)
|
||||
|
||||
# Buscar parámetros de tipo selection
|
||||
selection_params = env['lims.analysis.parameter'].search([
|
||||
('value_type', '=', 'selection'),
|
||||
('selection_values', '!=', False)
|
||||
], limit=5)
|
||||
|
||||
print(f"\nProbando con {len(selection_params)} parámetros tipo selection:\n")
|
||||
|
||||
for param in selection_params:
|
||||
print(f"Parámetro: {param.name} (ID: {param.id})")
|
||||
print(f" - selection_values (raw): '{param.selection_values}'")
|
||||
|
||||
# Llamar al método get_selection_list
|
||||
try:
|
||||
selection_list = param.get_selection_list()
|
||||
print(f" - get_selection_list(): {selection_list}")
|
||||
print(f" - Tipo: {type(selection_list)}")
|
||||
print(f" - Número de opciones: {len(selection_list)}")
|
||||
except Exception as e:
|
||||
print(f" - ERROR: {str(e)}")
|
||||
|
||||
print()
|
||||
|
||||
# Ahora verificar cómo se podría usar en lims.result
|
||||
print("\nVERIFICANDO USO EN lims.result:")
|
||||
print("-" * 40)
|
||||
|
||||
# Buscar un resultado con parámetro tipo selection
|
||||
result = env['lims.result'].search([
|
||||
('parameter_value_type', '=', 'selection')
|
||||
], limit=1)
|
||||
|
||||
if result:
|
||||
print(f"Resultado ID: {result.id}")
|
||||
print(f"Parámetro: {result.parameter_id.name}")
|
||||
print(f"Valor actual: '{result.value_selection}'")
|
||||
|
||||
# Obtener las opciones disponibles
|
||||
options = result.parameter_id.get_selection_list()
|
||||
print(f"Opciones disponibles: {options}")
|
||||
|
||||
# Verificar si el valor actual está en las opciones
|
||||
if result.value_selection in options:
|
||||
print("✓ El valor actual está en las opciones")
|
||||
else:
|
||||
print("✗ El valor actual NO está en las opciones")
|
||||
|
||||
# Simular asignación de un valor válido
|
||||
if options:
|
||||
print(f"\nSimulando asignación del primer valor válido: '{options[0]}'")
|
||||
# No hacemos write para no modificar datos
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
db_name = 'lims_demo'
|
||||
odoo.tools.config.parse_config(['--database', db_name])
|
||||
registry = odoo.registry(db_name)
|
||||
|
||||
with registry.cursor() as cr:
|
||||
env = odoo.api.Environment(cr, 1, {})
|
||||
test_get_selection_list(env)
|
116
test/test_selection_fix.py
Normal file
116
test/test_selection_fix.py
Normal file
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Script para probar la solución del bug de selection
|
||||
"""
|
||||
|
||||
import odoo
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def test_selection_fix(env):
|
||||
"""Probar que la solución funciona correctamente"""
|
||||
|
||||
print("=" * 80)
|
||||
print("PRUEBA DE SOLUCIÓN PARA BUG DE SELECTION")
|
||||
print("=" * 80)
|
||||
|
||||
# Crear una orden de prueba
|
||||
patient = env['res.partner'].search([('is_patient', '=', True)], limit=1)
|
||||
if not patient:
|
||||
patient = env['res.partner'].create({
|
||||
'name': 'Paciente Test Selection',
|
||||
'is_patient': True,
|
||||
})
|
||||
|
||||
# Buscar análisis con parámetros tipo selection
|
||||
# Por ejemplo: Prueba de Embarazo
|
||||
product = env['product.template'].search([
|
||||
('is_analysis', '=', True),
|
||||
('name', 'ilike', 'embarazo')
|
||||
], limit=1)
|
||||
|
||||
if not product:
|
||||
print("No se encontró el análisis de Prueba de Embarazo")
|
||||
return False
|
||||
|
||||
# Crear orden
|
||||
order = env['sale.order'].create({
|
||||
'partner_id': patient.id,
|
||||
'is_lab_request': True,
|
||||
'order_line': [(0, 0, {
|
||||
'product_id': product.product_variant_id.id,
|
||||
'product_uom_qty': 1,
|
||||
})]
|
||||
})
|
||||
|
||||
# Confirmar orden
|
||||
order.action_confirm()
|
||||
print(f"\nOrden creada: {order.name}")
|
||||
|
||||
# Obtener la prueba generada
|
||||
test = order.lab_test_ids[0]
|
||||
print(f"Prueba: {test.name}")
|
||||
|
||||
# Generar resultados
|
||||
test.sudo()._generate_test_results()
|
||||
print(f"Resultados generados: {len(test.result_ids)}")
|
||||
|
||||
# Verificar el resultado con parámetro tipo selection
|
||||
for result in test.result_ids:
|
||||
if result.parameter_value_type == 'selection':
|
||||
print(f"\nResultado de tipo selection encontrado:")
|
||||
print(f" - Parámetro: {result.parameter_id.name}")
|
||||
print(f" - Opciones en parámetro: {result.parameter_id.selection_values}")
|
||||
print(f" - Opciones disponibles: {result.selection_options_display}")
|
||||
|
||||
# Verificar que el campo computed funciona
|
||||
if result.selection_options_display:
|
||||
print(" ✓ Campo selection_options_display funciona correctamente")
|
||||
|
||||
# Simular asignación de valor
|
||||
options = result.parameter_id.get_selection_list()
|
||||
if options:
|
||||
result.value_selection = options[0]
|
||||
print(f" ✓ Valor asignado: '{result.value_selection}'")
|
||||
else:
|
||||
print(" ✗ No se muestran las opciones disponibles")
|
||||
|
||||
return True
|
||||
|
||||
print("\nNo se encontraron resultados de tipo selection")
|
||||
return False
|
||||
|
||||
|
||||
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:
|
||||
# Probar la solución
|
||||
success = test_selection_fix(env)
|
||||
|
||||
if success:
|
||||
print("\n✅ La solución funciona correctamente")
|
||||
else:
|
||||
print("\n❌ La prueba falló")
|
||||
|
||||
# No guardar cambios, solo probar
|
||||
cr.rollback()
|
||||
|
||||
except Exception as e:
|
||||
cr.rollback()
|
||||
print(f"\n❌ Error durante la prueba: {str(e)}")
|
||||
_logger.error(f"Error probando fix: {str(e)}", exc_info=True)
|
Loading…
Reference in New Issue
Block a user