diff --git a/backend/api/v1/modules/a76/reports/importacion/facturas/mex/service.py b/backend/api/v1/modules/a76/reports/importacion/facturas/mex/service.py index 69d502f4..bd0cd750 100644 --- a/backend/api/v1/modules/a76/reports/importacion/facturas/mex/service.py +++ b/backend/api/v1/modules/a76/reports/importacion/facturas/mex/service.py @@ -104,7 +104,8 @@ class FacturaImportacionMexService: if broker: nombre_agente = broker.name company = db.query(Company).filter(Company.id == header.company_id).first() - cliente_vendido = ClienteSchema( + # Datos Default (Company/Importer) - Used for fallback or Right Side (Enviado A) + cliente_default = ClienteSchema( header="Importador / Consignatario", nombre=getattr(company, 'name', "Empresa Local"), direccion="DOMICILIO FISCAL", @@ -113,6 +114,20 @@ class FacturaImportacionMexService: programa=getattr(company, 'program', "IMMEX"), autorizacion=getattr(company, 'program_number', "") ) + # Left Side Logic (Consignatario / Sold To) + cliente_vendido = cliente_default + if compliance and compliance.sold_to_id: + # Clean header: "vendido_a" -> "VENDIDO A" + raw_header = compliance.sold_to_header or "CONSIGNATARIO" + clean_header = raw_header.replace("_", " ").upper() + + # Fetch client data + cliente_vendido = self._obtener_datos_cliente(db, compliance.sold_to_id, clean_header) + + # Right Side Logic (Enviado A) - Currently keeping default/company info as requested "solo la izquierda" + # If standard logic dictates this should be Shipped To, we could add that later. + cliente_enviado = cliente_default + remesa_valor = str(compliance.remesa) if (compliance and compliance.remesa) else "" acuse_valor = str(compliance.edocument) if (compliance and compliance.edocument) else "N/A" @@ -210,7 +225,7 @@ class FacturaImportacionMexService: return FacturaImportacionCompleta( cliente_proveedor=cliente_proveedor, cliente_vendido=cliente_vendido, - cliente_enviado=cliente_vendido, factura=factura_schema, + cliente_enviado=cliente_enviado, factura=factura_schema, partidas=partidas_list, totales=totales ) diff --git a/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte b/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte index 99c13fe4..c82acb6d 100644 --- a/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte +++ b/frontend/src/lib/components/dashboard/goods/parts/partForm.svelte @@ -143,7 +143,8 @@ part_photo: d.part_photo || '', is_active: d.is_active ?? true, sector: d.fa_data?.sector || '', - fraction_type: d.fa_data?.fraction_type || '' + fraction_type: d.fa_data?.fraction_type || '', + currency_type: '' // Initialize to match type }; // Ensure currency_type is mapped correctly if coming from DB (optional, depending on DB values) if (d.currency_key === 'MXN') formData.currency_type = 'NA'; @@ -383,25 +384,25 @@