Improve planning data normalization
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m25s

This commit is contained in:
Cauê Faleiros
2026-07-20 11:24:47 -03:00
parent 3066ba06a2
commit 9af5f296a7
9 changed files with 112 additions and 18 deletions

View File

@@ -10,6 +10,7 @@ import type { DateRange, ProductAnalyticsItem, ProductionOrderItem } from '../ty
import { exportToCSV, fetchProductAnalytics, fetchProductionOrders } from '../dataService';
import { encodeProductGroupKey, parseProductName, sortProductSizes } from '../productParsing';
import { formatColorLabel } from '../displayFormatters';
import { getPlanningStock } from '../planningStock';
type ReplenishmentStatus = 'need' | 'covered' | 'no_sales' | 'no_stock';
type ReplenishmentFilter = 'all' | ReplenishmentStatus;
@@ -174,7 +175,7 @@ const Replenishment = () => {
const dailySales = product.quantitySold / rangeDays;
const projectedDemand = dailySales * targetCoverageDays;
const openProductionQuantity = openProductionByProductId[product.id] || 0;
const availableQuantity = product.stock + openProductionQuantity;
const availableQuantity = getPlanningStock(product.stock) + openProductionQuantity;
const rawNeed = projectedDemand - availableQuantity;
const suggestedQuantity = Math.max(0, Math.ceil(rawNeed));
const daysOfCover = dailySales > 0 ? availableQuantity / dailySales : null;