2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 18:25:26 +00:00

Add barcode handler to scan stock item into location

This commit is contained in:
Oliver Walters
2021-01-29 00:28:50 +11:00
parent db6aae8a78
commit c00e367ae5
3 changed files with 53 additions and 9 deletions

View File

@ -339,6 +339,40 @@ class _QRViewState extends State<InvenTreeQRView> {
}
class StockItemScanIntoLocationHandler extends BarcodeHandler {
/**
* Barcode handler for scanning a provided StockItem into a scanned StockLocation
*/
final InvenTreeStockItem item;
StockItemScanIntoLocationHandler(this.item);
@override
Future<void> onBarcodeMatched(Map<String, dynamic> data) {
// If the barcode points to a 'stocklocation', great!
if (!data.containsKey('stocklocation')) {
showErrorDialog(
_context,
"Invalid Barcode",
"Barcode does not match a Stock Location",
onDismissed: _controller.resumeCamera,
);
} else {
// Extract location information
int location = data['stocklocation']['pk'] as int;
// Transfer stock to specified location
item.transferStock(location).then((response) {
print("Response: ${response.statusCode}");
_controller.dispose();
Navigator.of(_context).pop();
});
}
}
}
Future<void> scanQrCode(BuildContext context) async {
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeQRView(BarcodeScanHandler())));