fix: PricingService tolera ProductId=0 para compatibilidad con FastEntryPage
This commit is contained in:
@@ -22,12 +22,19 @@ public class PricingService
|
||||
public async Task<CalculatePriceResponse> CalculateAsync(CalculatePriceRequest request)
|
||||
{
|
||||
// 0. Obtener el Producto para saber el Precio Base
|
||||
// Si ProductId = 0, el llamador no seleccionó un producto (ej: FastEntryPage legacy).
|
||||
// En ese caso fallamos graciosamente con precio base 0.
|
||||
decimal productBasePrice = 0;
|
||||
if (request.ProductId > 0)
|
||||
{
|
||||
var product = await _productRepo.GetByIdAsync(request.ProductId);
|
||||
if (product == null) return new CalculatePriceResponse
|
||||
{
|
||||
TotalPrice = 0,
|
||||
Details = "Producto no encontrado."
|
||||
};
|
||||
productBasePrice = await _productRepo.GetCurrentPriceAsync(request.ProductId, request.StartDate == default ? DateTime.UtcNow : request.StartDate);
|
||||
}
|
||||
|
||||
// 1. Obtener Reglas
|
||||
var pricing = await _repo.GetByCategoryIdAsync(request.CategoryId);
|
||||
@@ -53,10 +60,8 @@ public class PricingService
|
||||
var words = cleanText.Split(new[] { ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
int realWordCount = words.Length;
|
||||
|
||||
// 3. Costo Base y Excedente
|
||||
// Obtenemos el precio actual del producto vigenciado, fallback a BasePrice (usando el repo)
|
||||
decimal productBasePrice = await _productRepo.GetCurrentPriceAsync(request.ProductId, request.StartDate == default ? DateTime.UtcNow : request.StartDate);
|
||||
decimal currentCost = productBasePrice; // Precio base incluye N palabras
|
||||
// 3. Costo Base y Excedente (productBasePrice ya viene resuelto desde sección 0)
|
||||
decimal currentCost = productBasePrice; // Precio base del Producto seleccionado
|
||||
|
||||
|
||||
// ¿Cuántas palabras extra cobramos?
|
||||
|
||||
Reference in New Issue
Block a user