Added components to article
This commit is contained in:
@ -92,6 +92,48 @@ class TourRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/// Scan a single BOM component locally. The server-side `scanArticle` call
|
||||
/// for the parent article is deferred until **every** component of the
|
||||
/// parent is fully scanned — only then does the parent count as loaded.
|
||||
Future<ScanResult> scanComponent(
|
||||
String deliveryId,
|
||||
String carId,
|
||||
String componentArticleNumber,
|
||||
) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
final tour = _tourStream.value!;
|
||||
final delivery = tour.deliveries.firstWhere(
|
||||
(d) => d.id == deliveryId,
|
||||
);
|
||||
|
||||
// Locate the parent article and the matching component.
|
||||
final parentArticle = delivery.findParentOfComponent(
|
||||
componentArticleNumber,
|
||||
);
|
||||
if (parentArticle == null) return ScanResult.notFound;
|
||||
|
||||
final component = parentArticle.findComponent(componentArticleNumber)!;
|
||||
|
||||
if (component.isFullyScanned) return ScanResult.alreadyScanned;
|
||||
|
||||
// ── Local-only increment ──
|
||||
component.scannedAmount += 1;
|
||||
|
||||
// ── When every component is done, sync the parent with the server ──
|
||||
if (parentArticle.isFullyScanned) {
|
||||
await service.scanArticle(parentArticle.internalId.toString());
|
||||
parentArticle.scannedAmount += 1;
|
||||
delivery.carId = int.tryParse(carId) ?? delivery.carId;
|
||||
await service.assignCar(deliveryId, carId);
|
||||
}
|
||||
|
||||
_tourStream.add(tour);
|
||||
return ScanResult.scanned;
|
||||
}
|
||||
|
||||
Future<void> unscan(
|
||||
String deliveryId,
|
||||
String articleId,
|
||||
|
||||
Reference in New Issue
Block a user