mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-15 03:35:28 +00:00
Sales order barcode (#466)
* Add barcode handler for allocating stock to sales order * Refactor sales order allocation fields * Improve barcode handling * Handle barcode scan from sales order line detail view * Remove debug statements
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||
import "package:inventree/api_form.dart";
|
||||
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/inventree/sales_order.dart";
|
||||
@ -77,5 +79,98 @@ class SOAddItemBarcodeHandler extends BarcodeHandler {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SOAllocateStockHandler extends BarcodeHandler {
|
||||
|
||||
SOAllocateStockHandler({this.salesOrder, this.lineItem, this.shipment});
|
||||
|
||||
InvenTreeSalesOrder? salesOrder;
|
||||
InvenTreeSOLineItem? lineItem;
|
||||
InvenTreeSalesOrderShipment? shipment;
|
||||
|
||||
@override
|
||||
String getOverlayText(BuildContext context) => L10().allocateStock;
|
||||
|
||||
@override
|
||||
Future<void> processBarcode(String barcode,
|
||||
{
|
||||
String url = "barcode/so-allocate/",
|
||||
Map<String, dynamic> extra_data = const {}}) {
|
||||
|
||||
final so_extra_data = {
|
||||
"sales_order": salesOrder?.pk,
|
||||
"shipment": shipment?.pk,
|
||||
"line": lineItem?.pk,
|
||||
...extra_data
|
||||
};
|
||||
|
||||
return super.processBarcode(barcode, url: url, extra_data: so_extra_data);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||
if (!data.containsKey("line_item")) {
|
||||
return onBarcodeUnknown(data);
|
||||
}
|
||||
|
||||
barcodeSuccessTone();
|
||||
showSnackIcon(L10().allocated, success: true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
|
||||
|
||||
if (!data.containsKey("action_required") || !data.containsKey("line_item")) {
|
||||
return super.onBarcodeUnhandled(data);
|
||||
}
|
||||
|
||||
// Prompt user for extra information to create the allocation
|
||||
var fields = InvenTreeSOLineItem().allocateFormFields();
|
||||
|
||||
// Update fields with data gathered from the API response
|
||||
fields["line_item"]?["value"] = data["line_item"];
|
||||
|
||||
Map<String, dynamic> stock_filters = {
|
||||
"in_stock": true,
|
||||
"available": true,
|
||||
};
|
||||
|
||||
if (data.containsKey("part")) {
|
||||
stock_filters["part"] = data["part"];
|
||||
}
|
||||
|
||||
fields["stock_item"]?["filters"] = stock_filters;
|
||||
fields["stock_item"]?["value"] = data["stock_item"];
|
||||
|
||||
fields["quantity"]?["value"] = data["quantity"];
|
||||
|
||||
fields["shipment"]?["value"] = data["shipment"];
|
||||
fields["shipment"]?["filters"] = {
|
||||
"order": salesOrder!.pk.toString()
|
||||
};
|
||||
|
||||
final context = OneContext().context!;
|
||||
|
||||
launchApiForm(
|
||||
context,
|
||||
L10().allocateStock,
|
||||
salesOrder!.allocate_url,
|
||||
fields,
|
||||
method: "POST",
|
||||
icon: FontAwesomeIcons.rightToBracket,
|
||||
onSuccess: (data) async {
|
||||
showSnackIcon(L10().allocated, success: true);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
||||
barcodeFailureTone();
|
||||
showSnackIcon(
|
||||
data["error"] as String? ?? L10().barcodeError,
|
||||
success: false
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user