
- Cambiar view_mode de 'tree' a 'list' en menus.xml para action_lims_test - Cambiar mode='tree' a 'list' en lims_test_views.xml para campo result_ids - Corregir script create_demo_data.py: * Comentar campo inexistente 'lab_request_priority' * Cambiar 'observations' por 'note' (campo estándar) * Cambiar 'lab_sample_ids' por 'generated_sample_ids' * Ajustar índices de pacientes para usar María González (femenina) para embarazo - Mejorar validación en lims_result.py: * Considerar False y 0.0 como equivalentes para campos numéricos * Solo requerir valores cuando la prueba no esté en estado 'draft' Resuelve el error "View types not defined tree found in act_window action 457" y permite confirmar órdenes con pruebas de selección correctamente. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
170 lines
7.8 KiB
Python
170 lines
7.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Script para investigar y confirmar la orden S00029
|
|
Error: "Para parámetros de selección solo se debe elegir una opción"
|
|
"""
|
|
|
|
import odoo
|
|
import sys
|
|
import json
|
|
import traceback
|
|
|
|
def investigate_order(cr):
|
|
"""Investigar la orden S00029 y sus detalles"""
|
|
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
|
|
|
|
# Buscar la orden S00029
|
|
order = env['sale.order'].search([('name', '=', 'S00029')], limit=1)
|
|
if not order:
|
|
print("❌ No se encontró la orden S00029")
|
|
return
|
|
|
|
print(f"✓ Orden encontrada: {order.name}")
|
|
print(f" Cliente: {order.partner_id.name}")
|
|
print(f" Estado: {order.state}")
|
|
print(f" Es solicitud de lab: {order.is_lab_request}")
|
|
print(f" Doctor: {order.doctor_id.name if order.doctor_id else 'N/A'}")
|
|
print(f" Líneas de orden: {len(order.order_line)}")
|
|
|
|
# Revisar las líneas de la orden
|
|
print("\n📋 Líneas de orden:")
|
|
for i, line in enumerate(order.order_line, 1):
|
|
print(f"\n Línea {i}:")
|
|
print(f" Producto: {line.product_id.name}")
|
|
print(f" Es análisis: {line.product_id.is_analysis}")
|
|
print(f" Cantidad: {line.product_uom_qty}")
|
|
|
|
# Verificar parámetros del análisis
|
|
if line.product_id.is_analysis:
|
|
# Los parámetros están en product.template, no en product.product
|
|
template = line.product_id.product_tmpl_id
|
|
params = template.parameter_ids
|
|
print(f" Parámetros configurados: {len(params)}")
|
|
|
|
# Ver detalles de parámetros con tipo selección
|
|
selection_params = params.filtered(lambda p: p.parameter_value_type == 'selection')
|
|
if selection_params:
|
|
print(f" ⚠️ Parámetros de selección encontrados: {len(selection_params)}")
|
|
for param_config in selection_params:
|
|
param = param_config.parameter_id
|
|
print(f" - {param.name} (código: {param.code})")
|
|
print(f" Opciones: {param.selection_options}")
|
|
|
|
# Verificar rangos y valores predeterminados
|
|
cr.execute("""
|
|
SELECT
|
|
id,
|
|
age_min,
|
|
age_max,
|
|
gender,
|
|
default_value_selection
|
|
FROM lims_parameter_range
|
|
WHERE parameter_id = %s
|
|
ORDER BY age_min, gender
|
|
""", (param.id,))
|
|
ranges = cr.fetchall()
|
|
print(f" Rangos definidos: {len(ranges)}")
|
|
|
|
# Verificar si hay múltiples valores por defecto para el mismo grupo
|
|
default_selections = [r[4] for r in ranges if r[4]]
|
|
if len(default_selections) > 1:
|
|
print(f" ⚠️ PROBLEMA: {len(default_selections)} valores predeterminados encontrados")
|
|
for r in ranges:
|
|
if r[4]:
|
|
print(f" - Rango ID {r[0]}: edad {r[1]}-{r[2]}, género {r[3]}, default: '{r[4]}'")
|
|
|
|
# Información del paciente para determinar qué rangos aplicarían
|
|
print(f"\n👤 Información del paciente:")
|
|
print(f" Nombre: {order.partner_id.name}")
|
|
print(f" Género: {order.partner_id.gender}")
|
|
print(f" Fecha nacimiento: {order.partner_id.birthdate_date}")
|
|
if order.partner_id.birthdate_date:
|
|
from datetime import date
|
|
today = date.today()
|
|
age = today.year - order.partner_id.birthdate_date.year
|
|
if today.month < order.partner_id.birthdate_date.month or \
|
|
(today.month == order.partner_id.birthdate_date.month and today.day < order.partner_id.birthdate_date.day):
|
|
age -= 1
|
|
print(f" Edad: {age} años")
|
|
|
|
# Intentar confirmar la orden
|
|
print("\n🔄 Intentando confirmar la orden...")
|
|
try:
|
|
# Primero, verificar si hay muestras generadas
|
|
print(f" Muestras generadas antes: {len(order.generated_sample_ids)}")
|
|
|
|
# Intentar confirmar
|
|
order.action_confirm()
|
|
print("✅ Orden confirmada exitosamente!")
|
|
print(f" Nuevo estado: {order.state}")
|
|
print(f" Muestras generadas después: {len(order.generated_sample_ids)}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error al confirmar: {str(e)}")
|
|
print("\n📊 Traceback completo:")
|
|
traceback.print_exc()
|
|
|
|
# Investigar más a fondo el error de parámetros de selección
|
|
if "parámetros de selección" in str(e):
|
|
print("\n🔍 Analizando el problema de parámetros de selección...")
|
|
|
|
# Buscar específicamente parámetros problemáticos para este paciente
|
|
patient_age = None
|
|
if order.partner_id.birthdate_date:
|
|
from datetime import date
|
|
today = date.today()
|
|
patient_age = today.year - order.partner_id.birthdate_date.year
|
|
if today.month < order.partner_id.birthdate_date.month or \
|
|
(today.month == order.partner_id.birthdate_date.month and today.day < order.partner_id.birthdate_date.day):
|
|
patient_age -= 1
|
|
|
|
patient_gender = order.partner_id.gender or 'other'
|
|
|
|
print(f"\n Buscando rangos aplicables para:")
|
|
print(f" - Edad: {patient_age}")
|
|
print(f" - Género: {patient_gender}")
|
|
|
|
# Verificar cada análisis de la orden
|
|
for line in order.order_line:
|
|
if line.product_id.is_analysis:
|
|
template = line.product_id.product_tmpl_id
|
|
for param_config in template.parameter_ids:
|
|
if param_config.parameter_value_type == 'selection':
|
|
param = param_config.parameter_id
|
|
|
|
# Buscar rangos aplicables
|
|
query = """
|
|
SELECT
|
|
id,
|
|
age_min,
|
|
age_max,
|
|
gender,
|
|
default_value_selection
|
|
FROM lims_parameter_range
|
|
WHERE parameter_id = %s
|
|
AND (age_min IS NULL OR age_min <= %s)
|
|
AND (age_max IS NULL OR age_max >= %s)
|
|
AND (gender IS NULL OR gender = %s OR gender = 'other')
|
|
AND default_value_selection IS NOT NULL
|
|
"""
|
|
cr.execute(query, (param.id, patient_age or 0, patient_age or 999, patient_gender))
|
|
applicable_ranges = cr.fetchall()
|
|
|
|
if len(applicable_ranges) > 1:
|
|
print(f"\n ⚠️ CONFLICTO en {param.name}:")
|
|
print(f" {len(applicable_ranges)} rangos con valores por defecto aplicables:")
|
|
for r in applicable_ranges:
|
|
print(f" - Rango ID {r[0]}: edad {r[1]}-{r[2]}, género {r[3]}, default: '{r[4]}'")
|
|
|
|
return order
|
|
|
|
if __name__ == '__main__':
|
|
db_name = 'lims_demo'
|
|
try:
|
|
registry = odoo.modules.registry.Registry(db_name)
|
|
with registry.cursor() as cr:
|
|
investigate_order(cr)
|
|
except Exception as e:
|
|
print(f"Error general: {e}")
|
|
traceback.print_exc() |