fix(release): keep ledger codes in the undo step and share bundles per sheet

Review fixes for ledger-first Make Nests:

- The release renest (offer, staged run, codes, note) moves into
  OpenNest.Desktop.ReleaseRenest, shared by the headless panel, the
  live main window and the tests. Codes are given inside each commit, so
  the live tab's Auto Nest undo step records them; before, undo and redo
  dropped every ledger code.
- A bundle repeats one code per sheet: a later nest of the run lost the
  whole bundle once an earlier nest took one sheet. Taken sheets are now
  counted per code (LedgerCodeFilter.ExcludeCopies).
- A stage whose layout is not kept lists every copy it asked for as not
  placed (the proposal cannot be kept), and a rejected ledger layout
  says "MaterialLedger not used: Auto Nest could not keep a layout on
  its stock" instead of a bare "No MaterialLedger stock used".
- "no free stock" is said only when the ledger had none; otherwise the
  note counts what was left out (on other nests, taken by earlier nests
  of this release, too small, unknown shape).
- The ledger is not read for a nest with nothing to nest, the live read
  runs under the tab's stop token, a reason's own full stop is not
  doubled, and the sheet count is the codes given.
This commit is contained in:
aj committed 2026-11-03 17:53:26 -05:00
1 parent 31ee77914f
commit c5b6e680cb
10 files changed
+580 -251

No files matched your search

@@ -20,13 +20,41 @@ public static class LedgerCodeFilter
ArgumentNullException.ThrowIfNull(rows);
ArgumentNullException.ThrowIfNull(codesInUse);
var exclude = codesInUse as IReadOnlySet<string> ?? codesInUse.ToHashSet(StringComparer.Ordinal);
return Rebuild(rows, exclude.Contains, out removed);
}
/// <summary>
/// <paramref name="rows"/> with only <paramref name="copies"/> of each code taken out, in
/// row and ledger order: a bundle whose one code repeats per sheet loses as many sheets
/// as were taken, not the whole bundle. Otherwise as
/// <see cref="Exclude(IEnumerable{LedgerStockRow}, IEnumerable{string}, out int)"/>.
/// </summary>
public static IReadOnlyList<LedgerStockRow> ExcludeCopies(IEnumerable<LedgerStockRow> rows,
IReadOnlyDictionary<string, int> copies, out int removed)
{
ArgumentNullException.ThrowIfNull(rows);
ArgumentNullException.ThrowIfNull(copies);
var left = new Dictionary<string, int>(copies, StringComparer.Ordinal);
return Rebuild(rows, code =>
{
if (!left.TryGetValue(code, out var count) || count <= 0)
return false;
left[code] = count - 1;
return true;
}, out removed);
}
// takeOut is asked once per copy, in row order and the ledger order within a row.
private static IReadOnlyList<LedgerStockRow> Rebuild(IEnumerable<LedgerStockRow> rows,
Func<string, bool> takeOut, out int removed)
{
removed = 0;
var kept = new List<LedgerStockRow>();
foreach (var row in rows)
{
if (row == null)
continue;
var codes = row.ItemCodes.Where(code => !exclude.Contains(code)).ToList();
var codes = row.ItemCodes.Where(code => !takeOut(code)).ToList();
var dropped = row.ItemCodes.Count - codes.Count;
if (dropped == 0)
{
@@ -37,8 +65,9 @@ public static class LedgerCodeFilter
if (codes.Count == 0)
continue;
var left = codes.ToHashSet(StringComparer.Ordinal);
var itemLocations = row.ItemLocations
.Where(pair => !exclude.Contains(pair.Key))
.Where(pair => left.Contains(pair.Key) || !row.ItemCodes.Contains(pair.Key))
.ToDictionary(pair => pair.Key, pair => pair.Value, StringComparer.Ordinal);
// A location stays listed while an item left in the row is there, or when the row
// never said which item it held.