
- Mantener campo value_selection como Char con validación - Remover campos y métodos no utilizados (value_selection_field, _get_selection_values) - Mostrar opciones disponibles debajo del campo para guiar al usuario - La validación se mantiene en el constraint para asegurar valores válidos
132 lines
4.4 KiB
Python
132 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Script para crear datos de prueba con parámetros de tipo selection
|
|
"""
|
|
|
|
import odoo
|
|
import logging
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
def create_test_selection_data(env):
|
|
"""Crear datos de prueba para verificar el widget selection"""
|
|
|
|
print("=" * 80)
|
|
print("CREANDO DATOS DE PRUEBA PARA SELECTION")
|
|
print("=" * 80)
|
|
|
|
# Buscar o crear paciente
|
|
patient = env['res.partner'].search([('is_patient', '=', True)], limit=1)
|
|
if not patient:
|
|
patient = env['res.partner'].create({
|
|
'name': 'Paciente Test Selection Widget',
|
|
'is_patient': True,
|
|
})
|
|
print(f"Paciente creado: {patient.name}")
|
|
|
|
# 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 product:
|
|
print(f"\nAnálisis encontrado: {product.name}")
|
|
|
|
# Verificar parámetros asociados
|
|
print("\nParámetros del análisis:")
|
|
for param_link in product.parameter_ids:
|
|
param = param_link.parameter_id
|
|
print(f" - {param.name} (Tipo: {param.value_type})")
|
|
if param.value_type == 'selection':
|
|
print(f" Valores: '{param.selection_values}'")
|
|
print(f" Lista: {param.get_selection_list()}")
|
|
else:
|
|
print("No se encontró análisis de Prueba de Embarazo")
|
|
|
|
# Buscar cualquier análisis con parámetros selection
|
|
sql = """
|
|
SELECT DISTINCT pt.id, pt.name
|
|
FROM product_template pt
|
|
JOIN product_template_parameter ptp ON ptp.product_template_id = pt.id
|
|
JOIN lims_analysis_parameter lap ON lap.id = ptp.parameter_id
|
|
WHERE pt.is_analysis = true
|
|
AND lap.value_type = 'selection'
|
|
LIMIT 5
|
|
"""
|
|
env.cr.execute(sql)
|
|
results = env.cr.fetchall()
|
|
|
|
if results:
|
|
print("\nAnálisis con parámetros selection encontrados:")
|
|
for prod_id, prod_name in results:
|
|
print(f" - {prod_name} (ID: {prod_id})")
|
|
product = env['product.template'].browse(prod_id)
|
|
break
|
|
else:
|
|
print("No se encontraron análisis con parámetros selection")
|
|
return
|
|
|
|
# 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
|
|
if order.lab_test_ids:
|
|
test = order.lab_test_ids[0]
|
|
print(f"Prueba generada: {test.name} (ID: {test.id})")
|
|
|
|
# Generar resultados si no existen
|
|
if not test.result_ids:
|
|
test.sudo()._generate_test_results()
|
|
|
|
print(f"\nResultados generados:")
|
|
for result in test.result_ids:
|
|
print(f" - {result.parameter_id.name} (Tipo: {result.parameter_value_type})")
|
|
if result.parameter_value_type == 'selection':
|
|
print(f" ID del resultado: {result.id}")
|
|
print(f" Valores en parámetro: '{result.parameter_id.selection_values}'")
|
|
print(f" get_selection_list(): {result.parameter_id.get_selection_list()}")
|
|
print(f" _get_selection_options(): {result._get_selection_options()}")
|
|
print(f" selection_options_display: '{result.selection_options_display}'")
|
|
|
|
# Guardar cambios
|
|
env.cr.commit()
|
|
print("\n✅ Datos de prueba creados exitosamente")
|
|
|
|
|
|
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:
|
|
# Crear datos de prueba
|
|
create_test_selection_data(env)
|
|
|
|
except Exception as e:
|
|
cr.rollback()
|
|
print(f"\n❌ Error: {str(e)}")
|
|
_logger.error(f"Error: {str(e)}", exc_info=True) |