mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 06:03:12 +00:00
fix(work-orders): keep pendingUpliftCount on detail and exclude deleted dispatches
Map board PendingUpliftCount through WorkOrderDetailService.MapInfo and ignore soft-deleted dispatches in the aggregate so SH-188 gating is authoritative for board/search/detail.
This commit is contained in:
parent
aaeeb90f1a
commit
29dec00790
4 changed files with 93 additions and 1 deletions
|
|
@ -72,12 +72,13 @@ namespace SeaHaven.DataServices.Helpers
|
|||
w.PrimaryDispatchId,
|
||||
w.RowVersion,
|
||||
DispatchRowVersion = w.PrimaryDispatch != null ? w.PrimaryDispatch.RowVersion : null,
|
||||
// SH-188: aggregate Pending uplifts on every dispatch tied to this WO
|
||||
// SH-188: aggregate Pending uplifts on every live dispatch tied to this WO
|
||||
// (primary WorkOrderId and multi-WO DispatchWorkOrders links).
|
||||
PendingUpliftCount = context.DispatchUpliftRequests.Count(u =>
|
||||
u.Status == "Pending"
|
||||
&& (u.IsDeleted == null || u.IsDeleted == false)
|
||||
&& u.Dispatch != null
|
||||
&& (u.Dispatch.IsDeleted == null || u.Dispatch.IsDeleted == false)
|
||||
&& (
|
||||
u.Dispatch.WorkOrderId == w.Id
|
||||
|| u.Dispatch.DispatchWorkOrders!.Any(link => link.WorkOrderId == w.Id)))
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ namespace SeaHaven.Services.Implementation
|
|||
PrimaryDispatchId = row.PrimaryDispatchId,
|
||||
RowVersion = row.RowVersion,
|
||||
DispatchRowVersion = row.DispatchRowVersion,
|
||||
PendingUpliftCount = row.PendingUpliftCount,
|
||||
Description = extended?.Description,
|
||||
Trade = extended?.Trade,
|
||||
Problem = extended?.Problem,
|
||||
|
|
|
|||
|
|
@ -319,6 +319,56 @@ public class WorkOrderBoardPendingUpliftTests
|
|||
Assert.Equal(2, result.ScheduledRows[0].Id);
|
||||
Assert.Equal(1, result.ScheduledRows[0].PendingUpliftCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBoardRows_PendingUpliftOnSoftDeletedDispatch_DoesNotCount()
|
||||
{
|
||||
await using var context = CreateContext();
|
||||
var weekStart = new DateOnly(2026, 6, 22);
|
||||
|
||||
context.Vendors.Add(new Vendor { Id = 1, CompanyName = "Acme HVAC" });
|
||||
context.Dispatches.Add(new Dispatch
|
||||
{
|
||||
Id = 10,
|
||||
VendorId = 1,
|
||||
WorkOrderId = 1,
|
||||
ScheduledDate = new DateTime(2026, 6, 24, 8, 0, 0),
|
||||
IsDeleted = true
|
||||
});
|
||||
context.workOrders.Add(new WorkOrder
|
||||
{
|
||||
Id = 1,
|
||||
InternalWONumber = "10000000001",
|
||||
ScheduledDate = new DateTime(2026, 6, 23),
|
||||
LifecycleStatus = LifecycleStatus.Scheduled,
|
||||
PrimaryDispatchId = 10,
|
||||
SiteCode = "BK5"
|
||||
});
|
||||
context.DispatchUpliftRequests.Add(new DispatchUpliftRequest
|
||||
{
|
||||
Id = 100,
|
||||
DispatchId = 10,
|
||||
RequestedNTE = 1500m,
|
||||
Status = "Pending",
|
||||
RequiredTier = 1,
|
||||
NotificationStatus = "Pending"
|
||||
});
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
var service = new WorkOrderBoardDataService(context);
|
||||
var result = await service.GetBoardRowsAsync(new WorkOrderBoardQuery(
|
||||
weekStart,
|
||||
weekStart.AddDays(4),
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
null));
|
||||
|
||||
Assert.Single(result.ScheduledRows);
|
||||
Assert.Equal(0, result.ScheduledRows[0].PendingUpliftCount);
|
||||
}
|
||||
}
|
||||
|
||||
public class WorkOrderBoardServiceTests
|
||||
|
|
|
|||
|
|
@ -170,6 +170,46 @@ public class WorkOrderDetailServiceTests
|
|||
Assert.Equal("WeekRolled", detail.Audit[0].Action);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDetail_SurfacesPendingUpliftCountFromBoardRow()
|
||||
{
|
||||
var (context, service) = CreateSut();
|
||||
|
||||
context.Vendors.Add(new Vendor { Id = 1, CompanyName = "Acme HVAC" });
|
||||
context.Dispatches.Add(new Dispatch
|
||||
{
|
||||
Id = 10,
|
||||
VendorId = 1,
|
||||
WorkOrderId = 1,
|
||||
ScheduledDate = new DateTime(2026, 6, 24, 8, 0, 0)
|
||||
});
|
||||
context.workOrders.Add(new WorkOrder
|
||||
{
|
||||
Id = 1,
|
||||
InternalWONumber = "10000000001",
|
||||
LifecycleStatus = LifecycleStatus.Scheduled,
|
||||
ScheduledDate = DateTime.UtcNow.AddDays(1),
|
||||
PrimaryDispatchId = 10,
|
||||
SiteCode = "BK5",
|
||||
RowVersion = new byte[] { 1, 0, 0, 0, 0, 0, 0, 1 }
|
||||
});
|
||||
context.DispatchUpliftRequests.Add(new DispatchUpliftRequest
|
||||
{
|
||||
Id = 100,
|
||||
DispatchId = 10,
|
||||
RequestedNTE = 1500m,
|
||||
Status = "Pending",
|
||||
RequiredTier = 1,
|
||||
NotificationStatus = "Pending"
|
||||
});
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
var detail = await service.GetDetailAsync(1, WorkOrderAccountTestHelpers.OrgWideAdmin());
|
||||
|
||||
Assert.NotNull(detail);
|
||||
Assert.Equal(1, detail!.Info.PendingUpliftCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAudit_ResolvesAssignToUserIdsToDisplayNames()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue