fix: classify unlimited catalog-sourced job stock as in-stock
Task 7 extended JobStock.Quantity = -1 (unlimited) to catalog-sourced rows, but the post-pack classification step in CutListPackingService only ever treated a catalog-sourced bin as "in stock" when its tracked quantity was a positive finite number. An unlimited catalog row fell through to "to be purchased" even though IsInStock=true just means the bin is catalog-sourced, not a quantity check. This made the classification effectively unreachable for the most common path users take to stock a job: the "Import from Inventory" modal defaults every candidate's quantity to -1, so every resulting bin was mislabeled "to be purchased" on the Results tab, and the "everything is available in stock" message could never appear for jobs stocked that way. Track unlimited catalog-sourced lengths in a separate set and check it first; finite catalog quantities keep the existing decrementing-counter behavior, and custom-length stock (any quantity) is unaffected.
This commit is contained in:
@@ -108,7 +108,14 @@ public class CutListPackingService
|
||||
var inStockBins = new List<Bin>();
|
||||
var toBePurchasedBins = new List<Bin>();
|
||||
|
||||
// Track remaining in-stock quantities from the stock bins we configured
|
||||
// Catalog-sourced stock rows with an unlimited (-1) quantity are always in-stock,
|
||||
// regardless of how many bins of that length get packed.
|
||||
var unlimitedInStockLengths = stockBins
|
||||
.Where(s => s.IsInStock && s.Quantity == -1)
|
||||
.Select(s => s.LengthInches)
|
||||
.ToHashSet();
|
||||
|
||||
// Track remaining in-stock quantities from the finite-quantity catalog stock bins we configured
|
||||
var remainingStock = stockBins
|
||||
.Where(s => s.IsInStock && s.Quantity > 0)
|
||||
.GroupBy(s => s.LengthInches)
|
||||
@@ -118,9 +125,14 @@ public class CutListPackingService
|
||||
{
|
||||
var binLength = (decimal)bin.Length;
|
||||
|
||||
// Check if this can come from in-stock
|
||||
if (remainingStock.TryGetValue(binLength, out var remaining) && remaining > 0)
|
||||
if (unlimitedInStockLengths.Contains(binLength))
|
||||
{
|
||||
// Unlimited catalog-sourced stock - always in-stock
|
||||
inStockBins.Add(bin);
|
||||
}
|
||||
else if (remainingStock.TryGetValue(binLength, out var remaining) && remaining > 0)
|
||||
{
|
||||
// Check if this can come from in-stock
|
||||
inStockBins.Add(bin);
|
||||
remainingStock[binLength] = remaining - 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user