NC de DESPACHO: lotes de la Entrega origen o de la factura, linea por linea. Versión 2.1.4.0

Si la linea de la factura viene de una Entrega (BaseType 15) los lotes se
toman de la linea de la Entrega (BaseLine); si no, de la linea de la factura
(LineNum). Se valida que los lotes cubran la cantidad y se devuelve un error
claro por linea en vez del error generico de SAP.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
GeorgeandClaude Sonnet 5.5 committed 2026-10-14 10:29:02 -05:00
1 parent 6386070f4e
commit 14fffa8ba4
6 files changed
+94 -5

No files matched your search

@@ -13,5 +13,6 @@ namespace Net.Data.ServicesLayer
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateInvoices(BE_Invoices entidad);
Task<BE_ResultadoTransaccion<BE_InvoicesConsulta>> GetInvoice(int docEntry);
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> ReOpen(int docEntry);
Task<BE_ResultadoTransaccion<BE_DeliveryNotesConsulta>> GetDeliveryNote(int docEntry);
}
}
@@ -92,6 +92,25 @@ namespace Net.Data.ServicesLayer
}
}
// GET DELIVERY NOTE (para obtener los lotes de la entrega origen de una factura)
public async Task<BE_ResultadoTransaccion<BE_DeliveryNotesConsulta>> GetDeliveryNote(int docEntry)
{
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
ResultadoTransaccion<BE_DeliveryNotesConsulta> resultadoTransaccion = new ResultadoTransaccion<BE_DeliveryNotesConsulta>(_metodoName, _aplicacionName);
try
{
string cadena = $"DeliveryNotes({docEntry})";
List<BE_DeliveryNotesConsulta> objectList = await _connectServiceLayer.GetAsync<BE_DeliveryNotesConsulta>(cadena, 0, true);
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList);
}
catch (Exception ex)
{
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
}
}
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> ReOpen(int docEntry)
{
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
+41 -1
View File
@@ -213,13 +213,42 @@ namespace Net.Data.WMS.Picking
});
// == REALIZA DISTRIBUCION DE STOCK POR LOTE / ALMACEN
// Linea por linea: si la factura tiene una Entrega (BaseType 15) como documento
// origen, los lotes salen de la linea de esa Entrega (BaseLine); si no, de la
// propia linea de la factura (LineNum).
var Entregas = new Dictionary<int, BE_DeliveryNotesConsulta>();
var ErroresLote = new List<string>();
creditNotesNotes.DocumentLines.ForEach(line =>
{
#region CONSULTA A HANA
//List<BE_ItemStock> ListaStock = HelperStock.Get(line.ItemCode, entidad.CodigoAlmacen);
var ReferenciaFactura = _invoices.DocumentLines.FirstOrDefault(t => t.LineNum == line.LineNum);
var ListaStock = _invoices.DocumentLines.FirstOrDefault(InvoiceLine => InvoiceLine.LineNum == ReferenciaFactura.BaseLine).BatchNumbers;
List<BE_InvoicesBatchNumbers> ListaStock;
if (ReferenciaFactura.BaseType == 15 && ReferenciaFactura.BaseEntry.HasValue && ReferenciaFactura.BaseLine.HasValue)
{
int DocEntryEntrega = ReferenciaFactura.BaseEntry.Value;
if (!Entregas.TryGetValue(DocEntryEntrega, out BE_DeliveryNotesConsulta Entrega))
{
var response_entrega = invoicestRepository.GetDeliveryNote(DocEntryEntrega).Result;
Entrega = (response_entrega.DocEntry == -1) ? null : response_entrega.ListData?.FirstOrDefault();
Entregas[DocEntryEntrega] = Entrega;
}
if (Entrega == null)
{
ErroresLote.Add($"Linea {line.LineNum} ({line.ItemCode}): no se pudo leer la Entrega {DocEntryEntrega} origen de la factura");
return;
}
var LineaEntrega = Entrega.DocumentLines?.FirstOrDefault(t => t.LineNum == ReferenciaFactura.BaseLine.Value);
ListaStock = LineaEntrega?.BatchNumbers ?? new List<BE_InvoicesBatchNumbers>();
}
else
{
ListaStock = ReferenciaFactura.BatchNumbers ?? new List<BE_InvoicesBatchNumbers>();
}
double CantidadPendiente = (double)line.Quantity;
var ListOrdenadaFecha = ListaStock;
@@ -240,9 +269,20 @@ namespace Net.Data.WMS.Picking
}
});
// Hay lotes de origen pero no alcanzan para la cantidad a devolver
if (ListaStock.Count > 0 && CantidadPendiente > 0.000001)
{
ErroresLote.Add($"Linea {line.LineNum} ({line.ItemCode}): los lotes de origen no cubren la cantidad {line.Quantity} (faltan {CantidadPendiente})");
}
#endregion
});
if (ErroresLote.Count > 0)
{
return resultadoTransaccion.GetInformacionResultado("SAP: No se pudo asignar lotes a la nota de credito. " + string.Join(" | ", ErroresLote), entidad);
}
if (creditNotesNotes.DocumentLines.Count > 0)
{
var result_creditNotesRepository = _creditNotesRepository.SetCreateCreditNotes(creditNotesNotes).Result;