mirror of
https://github.com/inventree/inventree-app.git
synced 2026-07-04 11:50:45 +00:00
Improve scan stock item in Issue 617 (#841)
* Support transfer location into sublocation. Fix notification override. Support continous scanning. * Perform linting as suggested * Reuse http client and cache the https setting (#845) This makes the app way faster by not having to redo the TCP and TLS handshake all the time and removing a disk read on each http request. * Bump version and release notes (#846) --------- Co-authored-by: Jorropo <jorropo.pgm@gmail.com> Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
+65
-12
@@ -75,23 +75,20 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
|
|||||||
if (data.containsKey("stockitem")) {
|
if (data.containsKey("stockitem")) {
|
||||||
int _item = (data["stockitem"]?["pk"] ?? -1) as int;
|
int _item = (data["stockitem"]?["pk"] ?? -1) as int;
|
||||||
|
|
||||||
// A valid stock location!
|
|
||||||
if (_item > 0) {
|
if (_item > 0) {
|
||||||
barcodeSuccessTone();
|
barcodeSuccessTone();
|
||||||
|
|
||||||
bool result = await onItemScanned(_item);
|
await onItemScanned(_item);
|
||||||
|
}
|
||||||
|
} else if (data.containsKey("stocklocation")) {
|
||||||
|
int _loc = (data["stocklocation"]?["pk"] ?? -1) as int;
|
||||||
|
|
||||||
if (result && OneContext.hasContext) {
|
if (_loc > 0) {
|
||||||
OneContext().pop();
|
barcodeSuccessTone();
|
||||||
return;
|
|
||||||
}
|
await onStockLocationScanned(_loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get to this point, something went wrong during the scan process
|
|
||||||
barcodeFailureTone();
|
|
||||||
|
|
||||||
showSnackIcon(L10().invalidStockItem, success: false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback function which runs when a valid StockItem is scanned
|
// Callback function which runs when a valid StockItem is scanned
|
||||||
@@ -99,6 +96,12 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
|
|||||||
// Re-implement this for particular subclass
|
// Re-implement this for particular subclass
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Callback function which runs when a valid StockLocation is scanned
|
||||||
|
Future<bool> onStockLocationScanned(int locationId) async {
|
||||||
|
// Re-implement this for particular subclass
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -171,6 +174,56 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
|||||||
@override
|
@override
|
||||||
String getOverlayText(BuildContext context) => L10().barcodeScanItem;
|
String getOverlayText(BuildContext context) => L10().barcodeScanItem;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> onStockLocationScanned(int locationId) async {
|
||||||
|
if (locationId == location.pk) {
|
||||||
|
barcodeFailureTone();
|
||||||
|
showSnackIcon(L10().invalidStockLocation, success: false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final scannedLocation =
|
||||||
|
await InvenTreeStockLocation().get(locationId)
|
||||||
|
as InvenTreeStockLocation?;
|
||||||
|
|
||||||
|
if (scannedLocation != null) {
|
||||||
|
if (scannedLocation.parentId == location.pk) {
|
||||||
|
barcodeFailureTone();
|
||||||
|
showSnackIcon(L10().itemInLocation, success: false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final response = await scannedLocation.update(
|
||||||
|
values: {"parent": location.pk.toString()},
|
||||||
|
expectedStatusCode: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
case 201:
|
||||||
|
barcodeSuccess(L10().barcodeScanIntoLocationSuccess);
|
||||||
|
return true;
|
||||||
|
case 400:
|
||||||
|
barcodeFailureTone();
|
||||||
|
showSnackIcon(L10().invalidStockLocation, success: false);
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
barcodeFailureTone();
|
||||||
|
showSnackIcon(
|
||||||
|
L10().barcodeScanIntoLocationFailure,
|
||||||
|
success: false,
|
||||||
|
actionText: L10().details,
|
||||||
|
onAction: () {
|
||||||
|
showErrorDialog(L10().barcodeError, response: response);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> onItemScanned(int itemId) async {
|
Future<bool> onItemScanned(int itemId) async {
|
||||||
final InvenTreeStockItem? item =
|
final InvenTreeStockItem? item =
|
||||||
@@ -186,7 +239,7 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
|||||||
// Item is already *in* the specified location
|
// Item is already *in* the specified location
|
||||||
if (item.locationId == location.pk) {
|
if (item.locationId == location.pk) {
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
showSnackIcon(L10().itemInLocation, success: true);
|
showSnackIcon(L10().itemInLocation, success: false);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
|
|||||||
Reference in New Issue
Block a user