production

This commit is contained in:
2026-08-28 11:13:15 +05:30
parent d7348e253f
commit 5723d373b2
162 changed files with 17924 additions and 7026 deletions

View File

@@ -95,9 +95,49 @@ abstract final class WorkBoundary {
/// middle of the morning on one that does not — so it is asked of the line,
/// through the same knob everything else here reads. See
/// [ServiceProfile.endsAtHub].
static bool isClosed(Map<String, dynamic> stop) {
///
/// ── Skipped closes, and why it has to close *here* ──
///
/// A skip used to leave the order open, and the Deliveries tab kept it under
/// its own heading on the argument that the rider looks for it where he left
/// it. The cost of that was **dual ownership**: the same stop sat in the
/// active queue *and* in Activity, so the two screens disagreed about whether
/// the rider still owed it a visit. One order, one owner — a stop he has
/// written off is a record, and records live on Activity.
///
/// ── Why the status alone cannot answer it ──
///
/// On the delivery leg the backend has no failed-attempt outcome. A
/// successful skip leaves the consignment `Out_for_Delivery`, so
/// `/miler/bookings` keeps returning the row as live delivery work for the
/// rest of the day, and [stopStatusOf] reads exactly what the server sent.
/// Asking only the payload therefore re-admits the stop on every poll and on
/// every cold start.
///
/// [closedIds] is the answer to that, and it is **not** a display flag: it is
/// the persisted record of a mutation that already succeeded — day-stamped,
/// scoped to this rider, tenant and line (see [WorkScope]) — written by the
/// completed and skipped stores at the moment the rider's action came back
/// OK. It is the same shape of evidence [pickupComplete] already takes from
/// `collectedIds`, and it survives the process that wrote it, which is the
/// whole point.
///
/// Clearing it is what a resume does: [removeSkippedBookings] drops the id
/// and the stop is live work again on the very next read. There is no second
/// place holding the same opinion.
static bool isClosed(
Map<String, dynamic> stop, {
Set<String> closedIds = const <String>{},
}) {
if (closedIds.isNotEmpty && closedIds.contains(MilkRun.idOf(stop))) {
return true;
}
final status = stopStatusOf(stop);
if (status == StopStatus.delivered || status.isCancelled) return true;
// Filed under its own word, never flattened into cancelled: a stop the
// rider walked away from and one the office called off are different
// records, and Activity slices them apart.
if (status.isSkipped) return true;
return status.isPicked && ServiceProfile.active.endsAtHub;
}
@@ -110,8 +150,12 @@ abstract final class WorkBoundary {
Map<String, dynamic> stop, {
Set<String> collectedIds = const <String>{},
Set<String> acceptedIds = const <String>{},
/// Orders written off today — delivered, cancelled or skipped — read back
/// from the completed and skipped stores. See [isClosed].
Set<String> closedIds = const <String>{},
}) {
if (isClosed(stop)) return WorkDomain.closed;
if (isClosed(stop, closedIds: closedIds)) return WorkDomain.closed;
final handedOver = switch (ServiceProfile.active.handoffAt) {
HandoffPoint.collected => pickupComplete(
@@ -139,12 +183,14 @@ abstract final class WorkBoundary {
Iterable<Map<String, dynamic>> day, {
Set<String> collectedIds = const <String>{},
Set<String> acceptedIds = const <String>{},
Set<String> closedIds = const <String>{},
}) => [
for (final stop in day)
if (domainOf(
stop,
collectedIds: collectedIds,
acceptedIds: acceptedIds,
closedIds: closedIds,
) ==
WorkDomain.delivery)
stop,
@@ -155,12 +201,14 @@ abstract final class WorkBoundary {
Iterable<Map<String, dynamic>> day, {
Set<String> collectedIds = const <String>{},
Set<String> acceptedIds = const <String>{},
Set<String> closedIds = const <String>{},
}) => [
for (final stop in day)
if (domainOf(
stop,
collectedIds: collectedIds,
acceptedIds: acceptedIds,
closedIds: closedIds,
) ==
WorkDomain.pickup)
stop,