mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-07 03:32:11 +00:00
feat(work-orders): derive Scheduled from date without assignee
This commit is contained in:
parent
1bdbc12292
commit
335390f746
2 changed files with 83 additions and 9 deletions
|
|
@ -46,7 +46,13 @@ namespace SeaHaven.Services.Helpers
|
||||||
=> field.Equals(WorkOrderBoardFieldNames.LifecycleStatus, StringComparison.OrdinalIgnoreCase) && isPastDue;
|
=> field.Equals(WorkOrderBoardFieldNames.LifecycleStatus, StringComparison.OrdinalIgnoreCase) && isPastDue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SHOC rule: Incomplete + specific scheduled date + assignee → Scheduled.
|
/// Concrete Schedule On: a calendar day is set and the row is not week-only.
|
||||||
|
/// </summary>
|
||||||
|
public static bool HasConcreteSchedule(DateTime? scheduledDate, bool? scheduleWeekOnly)
|
||||||
|
=> scheduledDate.HasValue && scheduleWeekOnly != true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Incomplete or Pending + concrete scheduled date → Scheduled. Assignee is not required.
|
||||||
/// Week-only targets do not auto-schedule (same as <see cref="WorkOrderDerivedFields.ApplyAutoScheduleIfEligible"/>).
|
/// Week-only targets do not auto-schedule (same as <see cref="WorkOrderDerivedFields.ApplyAutoScheduleIfEligible"/>).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool ShouldAutoSchedule(
|
public static bool ShouldAutoSchedule(
|
||||||
|
|
@ -54,10 +60,27 @@ namespace SeaHaven.Services.Helpers
|
||||||
DateTime? scheduledDate,
|
DateTime? scheduledDate,
|
||||||
string? assignTo,
|
string? assignTo,
|
||||||
bool? scheduleWeekOnly = null)
|
bool? scheduleWeekOnly = null)
|
||||||
=> status == LifecycleStatus.Incomplete
|
{
|
||||||
&& scheduleWeekOnly != true
|
_ = assignTo;
|
||||||
&& scheduledDate.HasValue
|
return ShouldPromoteToScheduled(status, scheduledDate, scheduleWeekOnly);
|
||||||
&& !string.IsNullOrWhiteSpace(assignTo);
|
}
|
||||||
|
|
||||||
|
public static bool ShouldPromoteToScheduled(
|
||||||
|
LifecycleStatus? status,
|
||||||
|
DateTime? scheduledDate,
|
||||||
|
bool? scheduleWeekOnly = null)
|
||||||
|
=> (status == LifecycleStatus.Incomplete || status == LifecycleStatus.Pending)
|
||||||
|
&& HasConcreteSchedule(scheduledDate, scheduleWeekOnly);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scheduled without a concrete date (cleared or week-only) → Pending. Later statuses are ignored.
|
||||||
|
/// </summary>
|
||||||
|
public static bool ShouldDemoteFromScheduled(
|
||||||
|
LifecycleStatus? status,
|
||||||
|
DateTime? scheduledDate,
|
||||||
|
bool? scheduleWeekOnly = null)
|
||||||
|
=> status == LifecycleStatus.Scheduled
|
||||||
|
&& !HasConcreteSchedule(scheduledDate, scheduleWeekOnly);
|
||||||
|
|
||||||
public static bool IsReschedule(DateTime? previousDate, DateTime? newDate)
|
public static bool IsReschedule(DateTime? previousDate, DateTime? newDate)
|
||||||
=> previousDate.HasValue
|
=> previousDate.HasValue
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,21 @@ public class WorkOrderBoardMutationRulesTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ShouldAutoSchedule_WhenIncompleteWithDateAndAssignee()
|
public void ShouldAutoSchedule_WhenIncompleteWithDate_DoesNotRequireAssignee()
|
||||||
{
|
{
|
||||||
Assert.True(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
Assert.True(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
||||||
LifecycleStatus.Incomplete,
|
LifecycleStatus.Incomplete,
|
||||||
new DateTime(2026, 6, 25),
|
new DateTime(2026, 6, 25),
|
||||||
"dispatcher-1"));
|
assignTo: null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldAutoSchedule_WhenPendingWithConcreteDate()
|
||||||
|
{
|
||||||
|
Assert.True(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
||||||
|
LifecycleStatus.Pending,
|
||||||
|
new DateTime(2026, 6, 25),
|
||||||
|
assignTo: null));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -41,7 +50,7 @@ public class WorkOrderBoardMutationRulesTests
|
||||||
Assert.False(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
Assert.False(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
||||||
LifecycleStatus.Scheduled,
|
LifecycleStatus.Scheduled,
|
||||||
new DateTime(2026, 6, 25),
|
new DateTime(2026, 6, 25),
|
||||||
"dispatcher-1"));
|
assignTo: null));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -50,10 +59,52 @@ public class WorkOrderBoardMutationRulesTests
|
||||||
Assert.False(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
Assert.False(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
||||||
LifecycleStatus.Incomplete,
|
LifecycleStatus.Incomplete,
|
||||||
new DateTime(2026, 6, 25),
|
new DateTime(2026, 6, 25),
|
||||||
"dispatcher-1",
|
assignTo: null,
|
||||||
scheduleWeekOnly: true));
|
scheduleWeekOnly: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldAutoSchedule_FalseWhenInProgress()
|
||||||
|
{
|
||||||
|
Assert.False(WorkOrderBoardMutationRules.ShouldAutoSchedule(
|
||||||
|
LifecycleStatus.InProgress,
|
||||||
|
new DateTime(2026, 6, 25),
|
||||||
|
assignTo: null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldDemoteFromScheduled_WhenDateCleared()
|
||||||
|
{
|
||||||
|
Assert.True(WorkOrderBoardMutationRules.ShouldDemoteFromScheduled(
|
||||||
|
LifecycleStatus.Scheduled,
|
||||||
|
scheduledDate: null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldDemoteFromScheduled_WhenWeekOnly()
|
||||||
|
{
|
||||||
|
Assert.True(WorkOrderBoardMutationRules.ShouldDemoteFromScheduled(
|
||||||
|
LifecycleStatus.Scheduled,
|
||||||
|
new DateTime(2026, 6, 25),
|
||||||
|
scheduleWeekOnly: true));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldDemoteFromScheduled_FalseWhenConcreteDateRemains()
|
||||||
|
{
|
||||||
|
Assert.False(WorkOrderBoardMutationRules.ShouldDemoteFromScheduled(
|
||||||
|
LifecycleStatus.Scheduled,
|
||||||
|
new DateTime(2026, 6, 25)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ShouldDemoteFromScheduled_FalseWhenInProgress()
|
||||||
|
{
|
||||||
|
Assert.False(WorkOrderBoardMutationRules.ShouldDemoteFromScheduled(
|
||||||
|
LifecycleStatus.InProgress,
|
||||||
|
scheduledDate: null));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CanPatchBoardField_AllowsOnlyFlagColorWhenCompleted()
|
public void CanPatchBoardField_AllowsOnlyFlagColorWhenCompleted()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue