diff --git a/lims_management/models/__pycache__/sale_order.cpython-312.pyc b/lims_management/models/__pycache__/sale_order.cpython-312.pyc index b3d9332..4a05057 100644 Binary files a/lims_management/models/__pycache__/sale_order.cpython-312.pyc and b/lims_management/models/__pycache__/sale_order.cpython-312.pyc differ diff --git a/lims_management/models/__pycache__/stock_lot.cpython-312.pyc b/lims_management/models/__pycache__/stock_lot.cpython-312.pyc index 35ca762..e690aed 100644 Binary files a/lims_management/models/__pycache__/stock_lot.cpython-312.pyc and b/lims_management/models/__pycache__/stock_lot.cpython-312.pyc differ diff --git a/lims_management/report/sample_label_report.xml b/lims_management/report/sample_label_report.xml index 41d5fc8..b78284c 100644 --- a/lims_management/report/sample_label_report.xml +++ b/lims_management/report/sample_label_report.xml @@ -58,14 +58,13 @@
- - - - - - + + +
+ +
diff --git a/test/check_sample_barcodes.py b/test/check_sample_barcodes.py new file mode 100644 index 0000000..5ad5ada --- /dev/null +++ b/test/check_sample_barcodes.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Script para verificar los códigos de barras de las muestras en la orden S00025 +""" +import odoo +import json +from datetime import datetime + +def check_order_samples(cr, order_name='S00025'): + """Verificar las muestras y sus códigos de barras para una orden específica""" + + # Buscar la orden + cr.execute(""" + SELECT id, name, state, is_lab_request + FROM sale_order + WHERE name = %s + """, (order_name,)) + + order = cr.fetchone() + if not order: + print(f"❌ No se encontró la orden {order_name}") + return + + print(f"✅ Orden encontrada: {order[1]}") + print(f" - ID: {order[0]}") + print(f" - Estado: {order[2]}") + print(f" - Es orden de lab: {order[3]}") + print("") + + # Buscar las muestras asociadas a la orden + cr.execute(""" + SELECT + sl.id, + sl.name, + sl.barcode, + sl.is_lab_sample, + sl.patient_id, + sl.collection_date, + sl.state, + sl.sample_type_product_id, + rp.name as patient_name + FROM stock_lot sl + LEFT JOIN res_partner rp ON sl.patient_id = rp.id + WHERE sl.id IN ( + SELECT lot_id + FROM sale_order_stock_lot_rel + WHERE order_id = %s + ) + """, (order[0],)) + + samples = cr.fetchall() + + if not samples: + print(f"❌ No se encontraron muestras para la orden {order_name}") + + # Verificar si hay relación en la tabla intermedia + cr.execute(""" + SELECT COUNT(*) + FROM sale_order_stock_lot_rel + WHERE order_id = %s + """, (order[0],)) + count = cr.fetchone()[0] + print(f" Registros en sale_order_stock_lot_rel: {count}") + return + + print(f"📋 Muestras encontradas: {len(samples)}") + print("-" * 80) + + for sample in samples: + print(f"Muestra ID: {sample[0]}") + print(f" - Nombre: {sample[1]}") + print(f" - Código de barras: {sample[2] or '❌ VACÍO'}") + print(f" - Es muestra de lab: {sample[3]}") + print(f" - Paciente: {sample[8]} (ID: {sample[4]})") + print(f" - Fecha recolección: {sample[5]}") + print(f" - Estado: {sample[6]}") + print(f" - Tipo muestra ID: {sample[7]}") + + # Si no tiene código de barras, generar uno de ejemplo + if not sample[2]: + print(f" ⚠️ FALTA CÓDIGO DE BARRAS - Ejemplo generado: {datetime.now().strftime('%y%m%d')}000001") + + print("-" * 40) + + # Verificar el campo generated_sample_ids + cr.execute(""" + SELECT COUNT(*) + FROM sale_order_stock_lot_rel + WHERE order_id = %s + """, (order[0],)) + + rel_count = cr.fetchone()[0] + print(f"\n📊 Resumen:") + print(f" - Total muestras en relación: {rel_count}") + print(f" - Muestras sin código de barras: {sum(1 for s in samples if not s[2])}") + + # Verificar si el campo barcode es calculado o almacenado + cr.execute(""" + SELECT + column_name, + data_type, + is_nullable, + column_default + FROM information_schema.columns + WHERE table_name = 'stock_lot' + AND column_name = 'barcode' + """) + + col_info = cr.fetchone() + if col_info: + print(f"\n🔍 Información del campo 'barcode':") + print(f" - Tipo de dato: {col_info[1]}") + print(f" - Permite NULL: {col_info[2]}") + print(f" - Valor por defecto: {col_info[3]}") + +if __name__ == '__main__': + print("🔍 Verificando códigos de barras para orden S00025...") + print("=" * 80) + + db_name = 'lims_demo' + try: + registry = odoo.registry(db_name) + with registry.cursor() as cr: + check_order_samples(cr, 'S00025') + except Exception as e: + print(f"❌ Error: {str(e)}") + print(" Asegúrate de ejecutar este script dentro del contenedor de Odoo") \ No newline at end of file