2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-16 12:15:31 +00:00

[refactor] Scan improvements (#577)

* Handle error on unexpected barcode response

* Add ManufacturerPart detail view

* Support barcode scanning for manufacturer part

* Refactoring for null checks

* Ignore selected errors in sentry

* Fix API implementation for ManufacturerPart

* Update release notes

* More error handling

* Decode quantity betterer

* Refactoring

* Add option to confirm checkin details

* Improve response handlign

* Cleanup

* Remove unused imports

* Fix async function

* Fix for assigning custom barcode

* Handle barcode scan result for company

* Fix

* Adjust scan priority

* Refactoring MODEL_TYPE

- Use instead of duplicated const strings

* @override fix
This commit is contained in:
Oliver
2024-12-14 15:24:23 +11:00
committed by GitHub
parent 6b179d108c
commit 524c5469f1
24 changed files with 576 additions and 220 deletions

View File

@ -1,9 +1,7 @@
import "package:flutter/material.dart";
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
import "package:inventree/preferences.dart";
import "package:one_context/one_context.dart";
import "package:inventree/l10.dart";
import "package:inventree/api_form.dart";
import "package:inventree/barcode/barcode.dart";
import "package:inventree/barcode/handler.dart";
@ -23,10 +21,11 @@ import "package:inventree/widget/snacks.dart";
*/
class POReceiveBarcodeHandler extends BarcodeHandler {
POReceiveBarcodeHandler({this.purchaseOrder, this.location});
POReceiveBarcodeHandler({this.purchaseOrder, this.location, this.lineItem});
InvenTreePurchaseOrder? purchaseOrder;
InvenTreeStockLocation? location;
InvenTreePOLineItem? lineItem;
@override
String getOverlayText(BuildContext context) => L10().barcodeReceivePart;
@ -34,11 +33,15 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
@override
Future<void> processBarcode(String barcode,
{String url = "barcode/po-receive/",
Map<String, dynamic> extra_data = const {}}) {
Map<String, dynamic> extra_data = const {}}) async {
final bool confirm = await InvenTreeSettingsManager().getBool(INV_PO_CONFIRM_SCAN, true);
final po_extra_data = {
"purchase_order": purchaseOrder?.pk,
"location": location?.pk,
"line_item": lineItem?.pk,
"auto_allocate": !confirm,
...extra_data,
};
@ -47,11 +50,13 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
@override
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
if (!data.containsKey("lineitem")) {
if (data.containsKey("lineitem") || data.containsKey("success")) {
barcodeSuccess(L10().receivedItem);
return;
} else {
return onBarcodeUnknown(data);
}
barcodeSuccess(L10().receivedItem);
}
@override
@ -66,49 +71,41 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
showSnackIcon(L10().missingData, success: false);
}
// Construct fields to receive
Map<String, dynamic> fields = {
"line_item": {
"parent": "items",
"nested": true,
"hidden": true,
"value": lineItemData["pk"] as int,
},
"quantity": {
"parent": "items",
"nested": true,
"value": lineItemData["quantity"] as double?,
},
"status": {
"parent": "items",
"nested": true,
},
"location": {
"value": lineItemData["location"] as int?,
},
"barcode": {
"parent": "items",
"nested": true,
"hidden": true,
"type": "barcode",
"value": data["barcode_data"] as String,
// At minimum, we need the line item ID value
final int? lineItemId = lineItemData["pk"] as int?;
if (lineItemId == null) {
barcodeFailureTone();
return;
}
InvenTreePOLineItem? lineItem = await InvenTreePOLineItem().get(lineItemId) as InvenTreePOLineItem?;
if (lineItem == null) {
barcodeFailureTone();
return;
}
// Next, extract the "optional" fields
// Extract information from the returned server response
double? quantity = double.tryParse((lineItemData["quantity"] ?? "0").toString());
int? destination = lineItemData["location"] as int?;
String? barcode = data["barcode_data"] as String?;
// Discard the barcode scanner at this stage
if (OneContext.hasContext) {
OneContext().pop();
}
await lineItem.receive(
OneContext().context!,
destination: destination,
quantity: quantity,
barcode: barcode,
onSuccess: () {
showSnackIcon(L10().receivedItem, success: true);
}
};
final context = OneContext().context!;
final purchase_order_pk = lineItemData["purchase_order"];
final receive_url = "${InvenTreePurchaseOrder().URL}${purchase_order_pk}/receive/";
launchApiForm(
context,
L10().receiveItem,
receive_url,
fields,
method: "POST",
icon: TablerIcons.transition_right,
onSuccess: (data) async {
showSnackIcon(L10().receivedItem, success: true);
}
);
}