enhance: Enhances reception product scanning
Refreshes the list of receptions on the main page after returning from the details view, ensuring the displayed data is up-to-date. Improves the product scanning logic by ensuring product lookups are specific to the current reception. This prevents misidentification of products across different receptions. Adds an error toast message when a scanned product is not found within the active reception's product list, providing immediate user feedback. Refactors product retrieval and existence checks for clarity and robustness.
This commit is contained in:
parent
db71578ded
commit
5f158fb24e
@ -82,9 +82,16 @@ class _ReceptionPageState extends ConsumerState<ReceptionPage> {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
final id = reception.id;
|
||||
ReceptionDetailsRoute(
|
||||
receptionId: id,
|
||||
).push(context);
|
||||
ReceptionDetailsRoute(receptionId: id)
|
||||
.push(context)
|
||||
.then(
|
||||
(v) => ref
|
||||
.read(
|
||||
receptionPageModelProvider
|
||||
.notifier,
|
||||
)
|
||||
.getAllReceptions(),
|
||||
);
|
||||
},
|
||||
child: StockPickingCard(
|
||||
synchronized:
|
||||
|
@ -103,9 +103,15 @@ class _ReceptionScanPageState extends ConsumerState<ReceptionScanPage>
|
||||
return;
|
||||
}
|
||||
// find product in local database
|
||||
final isProductExist = model.isProductExist(barcode: qrcodeValue);
|
||||
if (isProductExist) {
|
||||
final product = model.getProduct(barcode: qrcodeValue);
|
||||
final isProductExist = model.getProduct(
|
||||
receptionId: widget.receptionId,
|
||||
barcode: qrcodeValue,
|
||||
);
|
||||
if (isProductExist != null) {
|
||||
final product = model.getProduct(
|
||||
receptionId: widget.receptionId,
|
||||
barcode: qrcodeValue,
|
||||
);
|
||||
model.incrementMoveLineQuantity(
|
||||
barcode: qrcodeValue,
|
||||
receptionId: widget.receptionId,
|
||||
@ -163,12 +169,21 @@ class _ReceptionScanPageState extends ConsumerState<ReceptionScanPage>
|
||||
final model = ref.read(receptionScanPageModelProvider.notifier);
|
||||
mobileScannerController.stop();
|
||||
// find product in local database
|
||||
final isProductExist = model.isProductExist(barcode: qrcodeValue);
|
||||
if (isProductExist) {
|
||||
final product = model.getProduct(barcode: qrcodeValue);
|
||||
final isProductExist = model.getProduct(
|
||||
receptionId: widget.receptionId,
|
||||
barcode: qrcodeValue,
|
||||
);
|
||||
if (isProductExist != null) {
|
||||
final product = model.getProduct(
|
||||
receptionId: widget.receptionId,
|
||||
barcode: qrcodeValue,
|
||||
);
|
||||
model.incrementMoveLineQuantity(
|
||||
barcode: qrcodeValue,
|
||||
receptionId: widget.receptionId,
|
||||
onError: () {
|
||||
Toast.showError('Aucun produit trouvé.');
|
||||
},
|
||||
);
|
||||
//show dialog
|
||||
await showDialog(
|
||||
|
@ -4,7 +4,7 @@ import 'package:e_scan/backend/objectbox/objectbox_manager.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
part 'reception_scan_page_model.freezed.dart';
|
||||
|
||||
final receptionScanPageModelProvider =
|
||||
@ -31,26 +31,22 @@ class ReceptionScanPageModel
|
||||
}
|
||||
}
|
||||
|
||||
bool isProductExist({required String barcode}) {
|
||||
final productBox = objectboxManager.store.box<ProductEntity>();
|
||||
return productBox
|
||||
.query(ProductEntity_.barcode.equals(barcode))
|
||||
.build()
|
||||
.findFirst() !=
|
||||
null;
|
||||
}
|
||||
|
||||
ProductEntity? getProduct({required String barcode}) {
|
||||
final productBox = objectboxManager.store.box<ProductEntity>();
|
||||
return productBox
|
||||
.query(ProductEntity_.barcode.equals(barcode))
|
||||
.build()
|
||||
.findFirst();
|
||||
ProductEntity? getProduct({
|
||||
required int receptionId,
|
||||
required String barcode,
|
||||
}) {
|
||||
final stockPickingRecordBox = objectboxManager.store
|
||||
.box<StockPickingRecordEntity>();
|
||||
final stockPickingRecord = stockPickingRecordBox.get(receptionId);
|
||||
final moveEntity = stockPickingRecord?.moveIdsWithoutPackage
|
||||
.firstWhereOrNull((e) => e.productId.target?.barcode == barcode);
|
||||
return moveEntity?.productId.target;
|
||||
}
|
||||
|
||||
void incrementMoveLineQuantity({
|
||||
required String barcode,
|
||||
required int receptionId,
|
||||
VoidCallback? onError,
|
||||
}) {
|
||||
final moveLineBox = objectboxManager.store
|
||||
.box<MoveLineWithoutPackageEntity>();
|
||||
@ -59,10 +55,9 @@ class ReceptionScanPageModel
|
||||
final moveBox = objectboxManager.store.box<MoveWithoutPackageEntity>();
|
||||
final stockPickingRecord = stockPickingRecordBox.get(receptionId);
|
||||
final moveLineEntity = stockPickingRecord?.moveLineIdsWithoutPackage
|
||||
.firstWhere((e) => e.productId.target?.barcode == barcode);
|
||||
final moveEntity = stockPickingRecord?.moveIdsWithoutPackage.firstWhere(
|
||||
(e) => e.productId.target?.barcode == barcode,
|
||||
);
|
||||
.firstWhereOrNull((e) => e.productId.target?.barcode == barcode);
|
||||
final moveEntity = stockPickingRecord?.moveIdsWithoutPackage
|
||||
.firstWhereOrNull((e) => e.productId.target?.barcode == barcode);
|
||||
if (moveLineEntity != null &&
|
||||
moveEntity != null &&
|
||||
stockPickingRecord != null) {
|
||||
@ -72,6 +67,8 @@ class ReceptionScanPageModel
|
||||
moveLineBox.put(moveLineEntity);
|
||||
moveBox.put(moveEntity);
|
||||
stockPickingRecordBox.put(stockPickingRecord);
|
||||
} else {
|
||||
onError?.call();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ packages:
|
||||
source: hosted
|
||||
version: "4.10.1"
|
||||
collection:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: collection
|
||||
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
||||
|
@ -56,6 +56,7 @@ dependencies:
|
||||
path: ^1.9.1
|
||||
multiple_result: ^5.1.0
|
||||
toastification: ^3.0.3
|
||||
collection: ^1.19.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
x
Reference in New Issue
Block a user