mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 10:15:32 +00:00
Add POReceiveBarcodeHandler to support barcode/po-receive/ endpoint (#421)
* Add POReceiveBarcodeHandler to support barcode/po-receive/ endpoint * Remove german translation * Add api version checks * Add getOverlayText method to barcode handler * Bump required API version to 139 * Update barcode.dart The "quantity" field is not an integer, and can cause the app to crash if not handled correctly --------- Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
@ -6,6 +6,7 @@ import "package:one_context/one_context.dart";
|
||||
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/api_form.dart";
|
||||
import "package:inventree/helpers.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
@ -462,6 +463,116 @@ class ScanParentLocationHandler extends BarcodeScanStockLocationHandler {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Barcode handler class for scanning a supplier barcode to receive a part
|
||||
*
|
||||
* - The class can be initialized by optionally passing a valid, placed PurchaseOrder object
|
||||
* - Expects to scan supplier barcode, possibly containing order_number and quantity
|
||||
* - If location or quantity information wasn't provided, show a form to fill it in
|
||||
*/
|
||||
class POReceiveBarcodeHandler extends BarcodeHandler {
|
||||
|
||||
POReceiveBarcodeHandler({this.purchaseOrder, this.location});
|
||||
|
||||
InvenTreePurchaseOrder? purchaseOrder;
|
||||
InvenTreeStockLocation? location;
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => L10().barcodeReceivePart;
|
||||
|
||||
@override
|
||||
Future<void> processBarcode(String barcode,
|
||||
{String url = "barcode/po-receive/",
|
||||
Map<String, dynamic> extra_data = const {}}) {
|
||||
|
||||
final po_extra_data = {
|
||||
"purchase_order": purchaseOrder?.pk,
|
||||
"location": location?.pk,
|
||||
...extra_data,
|
||||
};
|
||||
|
||||
return super.processBarcode(barcode, url: url, extra_data: po_extra_data);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||
if (!data.containsKey("lineitem")) {
|
||||
return onBarcodeUnknown(data);
|
||||
}
|
||||
|
||||
barcodeSuccessTone();
|
||||
showSnackIcon(L10().receivedItem, success: true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
|
||||
if (!data.containsKey("action_required") || !data.containsKey("lineitem")) {
|
||||
return super.onBarcodeUnhandled(data);
|
||||
}
|
||||
|
||||
final lineItemData = data["lineitem"] as Map<String, dynamic>;
|
||||
if (!lineItemData.containsKey("pk") || !lineItemData.containsKey("purchase_order")) {
|
||||
barcodeFailureTone();
|
||||
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,
|
||||
}
|
||||
};
|
||||
|
||||
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: FontAwesomeIcons.rightToBracket,
|
||||
onSuccess: (data) async {
|
||||
showSnackIcon(L10().receivedItem, success: true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
||||
barcodeFailureTone();
|
||||
showSnackIcon(
|
||||
data["error"] as String? ?? L10().barcodeError,
|
||||
success: false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Barcode handler for finding a "unique" barcode (one that does not match an item in the database)
|
||||
*/
|
||||
|
Reference in New Issue
Block a user