From add94dff6c35f5009c0eb454e2304ae873c45ab7 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 19 Oct 2026 11:09:54 -0400 Subject: [PATCH] fix(data): leave the trailing empty plate out of nest record plate counts The editor keeps an empty plate at the end of a nest as its new-plate slot. Counting it made database records report one plate too many, so the record now uses the same displayed-plate count as the UI. Co-Authored-By: Claude Opus 5.5 --- OpenNest.Data/NestRecordFactory.cs | 3 ++- OpenNest.Tests/Data/NestRecordFactoryTests.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/OpenNest.Data/NestRecordFactory.cs b/OpenNest.Data/NestRecordFactory.cs index 8378e335..edb9c591 100644 --- a/OpenNest.Data/NestRecordFactory.cs +++ b/OpenNest.Data/NestRecordFactory.cs @@ -46,7 +46,8 @@ public static class NestRecordFactory Material = nest.Material?.Name ?? "", Thickness = nest.Thickness, Status = nest.Status, - PlateCount = nest.Plates.Count, + // The trailing empty plate is the editor's new-plate slot, not a plate of the nest. + PlateCount = PlateDisplayNumbering.DisplayedPlateCount(nest.Plates), PartCount = nest.Plates.Sum(CountNonCutoffParts), // Nest has no separate "comments" field; Notes is the closest analog // shown in the nest info dialog, so it round-trips as Comments here. diff --git a/OpenNest.Tests/Data/NestRecordFactoryTests.cs b/OpenNest.Tests/Data/NestRecordFactoryTests.cs index 1a5b0d68..46d974dc 100644 --- a/OpenNest.Tests/Data/NestRecordFactoryTests.cs +++ b/OpenNest.Tests/Data/NestRecordFactoryTests.cs @@ -115,6 +115,21 @@ public class NestRecordFactoryTests Assert.Equal("", record.MadeBy); } + [Fact] + public void FromNest_TrailingEmptyPlate_NotCounted() + { + var nest = new Nest("Sentinel"); + var drawing = new Drawing("A"); + nest.Drawings.Add(drawing); + nest.CreatePlate().Parts.Add(new Part(drawing)); + nest.CreatePlate(); + + var record = NestRecordFactory.FromNest(nest, Guid.NewGuid(), fileSize: 0); + + Assert.Equal(1, record.PlateCount); + Assert.Equal(1, record.PartCount); + } + [Fact] public void FromNest_PreservesGivenId() {