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(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
final id = reception.id;
|
final id = reception.id;
|
||||||
ReceptionDetailsRoute(
|
ReceptionDetailsRoute(receptionId: id)
|
||||||
receptionId: id,
|
.push(context)
|
||||||
).push(context);
|
.then(
|
||||||
|
(v) => ref
|
||||||
|
.read(
|
||||||
|
receptionPageModelProvider
|
||||||
|
.notifier,
|
||||||
|
)
|
||||||
|
.getAllReceptions(),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
child: StockPickingCard(
|
child: StockPickingCard(
|
||||||
synchronized:
|
synchronized:
|
||||||
|
@ -103,9 +103,15 @@ class _ReceptionScanPageState extends ConsumerState<ReceptionScanPage>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// find product in local database
|
// find product in local database
|
||||||
final isProductExist = model.isProductExist(barcode: qrcodeValue);
|
final isProductExist = model.getProduct(
|
||||||
if (isProductExist) {
|
receptionId: widget.receptionId,
|
||||||
final product = model.getProduct(barcode: qrcodeValue);
|
barcode: qrcodeValue,
|
||||||
|
);
|
||||||
|
if (isProductExist != null) {
|
||||||
|
final product = model.getProduct(
|
||||||
|
receptionId: widget.receptionId,
|
||||||
|
barcode: qrcodeValue,
|
||||||
|
);
|
||||||
model.incrementMoveLineQuantity(
|
model.incrementMoveLineQuantity(
|
||||||
barcode: qrcodeValue,
|
barcode: qrcodeValue,
|
||||||
receptionId: widget.receptionId,
|
receptionId: widget.receptionId,
|
||||||
@ -163,12 +169,21 @@ class _ReceptionScanPageState extends ConsumerState<ReceptionScanPage>
|
|||||||
final model = ref.read(receptionScanPageModelProvider.notifier);
|
final model = ref.read(receptionScanPageModelProvider.notifier);
|
||||||
mobileScannerController.stop();
|
mobileScannerController.stop();
|
||||||
// find product in local database
|
// find product in local database
|
||||||
final isProductExist = model.isProductExist(barcode: qrcodeValue);
|
final isProductExist = model.getProduct(
|
||||||
if (isProductExist) {
|
receptionId: widget.receptionId,
|
||||||
final product = model.getProduct(barcode: qrcodeValue);
|
barcode: qrcodeValue,
|
||||||
|
);
|
||||||
|
if (isProductExist != null) {
|
||||||
|
final product = model.getProduct(
|
||||||
|
receptionId: widget.receptionId,
|
||||||
|
barcode: qrcodeValue,
|
||||||
|
);
|
||||||
model.incrementMoveLineQuantity(
|
model.incrementMoveLineQuantity(
|
||||||
barcode: qrcodeValue,
|
barcode: qrcodeValue,
|
||||||
receptionId: widget.receptionId,
|
receptionId: widget.receptionId,
|
||||||
|
onError: () {
|
||||||
|
Toast.showError('Aucun produit trouvé.');
|
||||||
|
},
|
||||||
);
|
);
|
||||||
//show dialog
|
//show dialog
|
||||||
await showDialog(
|
await showDialog(
|
||||||
|
@ -4,7 +4,7 @@ import 'package:e_scan/backend/objectbox/objectbox_manager.dart';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
part 'reception_scan_page_model.freezed.dart';
|
part 'reception_scan_page_model.freezed.dart';
|
||||||
|
|
||||||
final receptionScanPageModelProvider =
|
final receptionScanPageModelProvider =
|
||||||
@ -31,26 +31,22 @@ class ReceptionScanPageModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isProductExist({required String barcode}) {
|
ProductEntity? getProduct({
|
||||||
final productBox = objectboxManager.store.box<ProductEntity>();
|
required int receptionId,
|
||||||
return productBox
|
required String barcode,
|
||||||
.query(ProductEntity_.barcode.equals(barcode))
|
}) {
|
||||||
.build()
|
final stockPickingRecordBox = objectboxManager.store
|
||||||
.findFirst() !=
|
.box<StockPickingRecordEntity>();
|
||||||
null;
|
final stockPickingRecord = stockPickingRecordBox.get(receptionId);
|
||||||
}
|
final moveEntity = stockPickingRecord?.moveIdsWithoutPackage
|
||||||
|
.firstWhereOrNull((e) => e.productId.target?.barcode == barcode);
|
||||||
ProductEntity? getProduct({required String barcode}) {
|
return moveEntity?.productId.target;
|
||||||
final productBox = objectboxManager.store.box<ProductEntity>();
|
|
||||||
return productBox
|
|
||||||
.query(ProductEntity_.barcode.equals(barcode))
|
|
||||||
.build()
|
|
||||||
.findFirst();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void incrementMoveLineQuantity({
|
void incrementMoveLineQuantity({
|
||||||
required String barcode,
|
required String barcode,
|
||||||
required int receptionId,
|
required int receptionId,
|
||||||
|
VoidCallback? onError,
|
||||||
}) {
|
}) {
|
||||||
final moveLineBox = objectboxManager.store
|
final moveLineBox = objectboxManager.store
|
||||||
.box<MoveLineWithoutPackageEntity>();
|
.box<MoveLineWithoutPackageEntity>();
|
||||||
@ -59,10 +55,9 @@ class ReceptionScanPageModel
|
|||||||
final moveBox = objectboxManager.store.box<MoveWithoutPackageEntity>();
|
final moveBox = objectboxManager.store.box<MoveWithoutPackageEntity>();
|
||||||
final stockPickingRecord = stockPickingRecordBox.get(receptionId);
|
final stockPickingRecord = stockPickingRecordBox.get(receptionId);
|
||||||
final moveLineEntity = stockPickingRecord?.moveLineIdsWithoutPackage
|
final moveLineEntity = stockPickingRecord?.moveLineIdsWithoutPackage
|
||||||
.firstWhere((e) => e.productId.target?.barcode == barcode);
|
.firstWhereOrNull((e) => e.productId.target?.barcode == barcode);
|
||||||
final moveEntity = stockPickingRecord?.moveIdsWithoutPackage.firstWhere(
|
final moveEntity = stockPickingRecord?.moveIdsWithoutPackage
|
||||||
(e) => e.productId.target?.barcode == barcode,
|
.firstWhereOrNull((e) => e.productId.target?.barcode == barcode);
|
||||||
);
|
|
||||||
if (moveLineEntity != null &&
|
if (moveLineEntity != null &&
|
||||||
moveEntity != null &&
|
moveEntity != null &&
|
||||||
stockPickingRecord != null) {
|
stockPickingRecord != null) {
|
||||||
@ -72,6 +67,8 @@ class ReceptionScanPageModel
|
|||||||
moveLineBox.put(moveLineEntity);
|
moveLineBox.put(moveLineEntity);
|
||||||
moveBox.put(moveEntity);
|
moveBox.put(moveEntity);
|
||||||
stockPickingRecordBox.put(stockPickingRecord);
|
stockPickingRecordBox.put(stockPickingRecord);
|
||||||
|
} else {
|
||||||
|
onError?.call();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "4.10.1"
|
version: "4.10.1"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: collection
|
name: collection
|
||||||
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
||||||
|
@ -56,6 +56,7 @@ dependencies:
|
|||||||
path: ^1.9.1
|
path: ^1.9.1
|
||||||
multiple_result: ^5.1.0
|
multiple_result: ^5.1.0
|
||||||
toastification: ^3.0.3
|
toastification: ^3.0.3
|
||||||
|
collection: ^1.19.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user