fix: PricingService tolera ProductId=0 para compatibilidad con FastEntryPage

This commit is contained in:
2026-02-21 19:55:08 -03:00
parent 6d1eb908a0
commit 16f84237fb

View File

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