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

Format code

This commit is contained in:
Asterix\Oliver
2025-06-14 10:59:13 +10:00
parent 0349ebb0b3
commit 387dc1eb39
96 changed files with 5478 additions and 7340 deletions

View File

@ -10,7 +10,6 @@ import "package:inventree/widget/company/manufacturer_part_detail.dart";
import "package:inventree/widget/order/sales_order_detail.dart";
import "package:one_context/one_context.dart";
import "package:inventree/api.dart";
import "package:inventree/l10.dart";
@ -35,10 +34,8 @@ import "package:inventree/widget/stock/stock_detail.dart";
import "package:inventree/widget/company/company_detail.dart";
import "package:inventree/widget/company/supplier_part_detail.dart";
// Signal a barcode scan success to the user
Future<void> barcodeSuccess(String msg) async {
barcodeSuccessTone();
showSnackIcon(msg, success: true);
}
@ -46,26 +43,18 @@ Future<void> barcodeSuccess(String msg) async {
// Signal a barcode scan failure to the user
Future<void> barcodeFailure(String msg, dynamic extra) async {
barcodeFailureTone();
showSnackIcon(
msg,
success: false,
onAction: () {
if (hasContext()) {
OneContext().showDialog(
builder: (BuildContext context) =>
SimpleDialog(
title: Text(L10().barcodeError),
children: <Widget>[
ListTile(
title: Text(L10().responseData),
subtitle: Text(extra.toString())
)
]
)
);
}
showSnackIcon(msg, success: false, onAction: () {
if (hasContext()) {
OneContext().showDialog(
builder: (BuildContext context) => SimpleDialog(
title: Text(L10().barcodeError),
children: <Widget>[
ListTile(
title: Text(L10().responseData),
subtitle: Text(extra.toString()))
]));
}
);
});
}
/*
@ -75,15 +64,16 @@ Future<void> barcodeFailure(String msg, dynamic extra) async {
* - Returns a Future which resolves when the scanner is dismissed
* - The provided BarcodeHandler instance is used to handle the scanned barcode
*/
Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) async {
Future<Object?> scanBarcode(BuildContext context,
{BarcodeHandler? handler}) async {
// Default to generic scan handler
handler ??= BarcodeScanHandler();
InvenTreeBarcodeController controller = CameraBarcodeController(handler);
// Select barcode controller based on user preference
final int barcodeControllerType = await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_TYPE, BARCODE_CONTROLLER_CAMERA) as int;
final int barcodeControllerType = await InvenTreeSettingsManager()
.getValue(INV_BARCODE_SCAN_TYPE, BARCODE_CONTROLLER_CAMERA) as int;
switch (barcodeControllerType) {
case BARCODE_CONTROLLER_WEDGE:
@ -95,15 +85,12 @@ Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) asy
break;
}
return Navigator.of(context).push(
PageRouteBuilder(
pageBuilder: (context, _, __) => controller,
opaque: false,
)
);
return Navigator.of(context).push(PageRouteBuilder(
pageBuilder: (context, _, __) => controller,
opaque: false,
));
}
/*
* Class for general barcode scanning.
* Scan *any* barcode without context, and then redirect app to correct view.
@ -117,19 +104,17 @@ Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) asy
* - PurchaseOrder
*/
class BarcodeScanHandler extends BarcodeHandler {
@override
String getOverlayText(BuildContext context) => L10().barcodeScanGeneral;
@override
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
barcodeFailureTone();
showSnackIcon(
L10().barcodeNoMatch,
icon: TablerIcons.exclamation_circle,
success: false,
L10().barcodeNoMatch,
icon: TablerIcons.exclamation_circle,
success: false,
);
}
@ -137,12 +122,12 @@ class BarcodeScanHandler extends BarcodeHandler {
* Response when a "Part" instance is scanned
*/
Future<void> handlePart(int pk) async {
var part = await InvenTreePart().get(pk);
if (part is InvenTreePart) {
OneContext().pop();
OneContext().push(MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
OneContext().push(
MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
}
}
@ -150,13 +135,12 @@ class BarcodeScanHandler extends BarcodeHandler {
* Response when a "StockItem" instance is scanned
*/
Future<void> handleStockItem(int pk) async {
var item = await InvenTreeStockItem().get(pk);
if (item is InvenTreeStockItem) {
OneContext().pop();
OneContext().push(MaterialPageRoute(
builder: (context) => StockDetailWidget(item)));
OneContext().push(
MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
}
}
@ -164,13 +148,12 @@ class BarcodeScanHandler extends BarcodeHandler {
* Response when a "StockLocation" instance is scanned
*/
Future<void> handleStockLocation(int pk) async {
var loc = await InvenTreeStockLocation().get(pk);
if (loc is InvenTreeStockLocation) {
OneContext().pop();
OneContext().navigator.push(MaterialPageRoute(
builder: (context) => LocationDisplayWidget(loc)));
OneContext().navigator.push(
MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
}
}
@ -178,7 +161,6 @@ class BarcodeScanHandler extends BarcodeHandler {
* Response when a "SupplierPart" instance is scanned
*/
Future<void> handleSupplierPart(int pk) async {
var supplierPart = await InvenTreeSupplierPart().get(pk);
if (supplierPart is InvenTreeSupplierPart) {
@ -197,7 +179,8 @@ class BarcodeScanHandler extends BarcodeHandler {
if (manufacturerPart is InvenTreeManufacturerPart) {
OneContext().pop();
OneContext().push(MaterialPageRoute(
builder: (context) => ManufacturerPartDetailWidget(manufacturerPart)));
builder: (context) =>
ManufacturerPartDetailWidget(manufacturerPart)));
}
}
@ -220,7 +203,7 @@ class BarcodeScanHandler extends BarcodeHandler {
if (order is InvenTreePurchaseOrder) {
OneContext().pop();
OneContext().push(MaterialPageRoute(
builder: (context) => PurchaseOrderDetailWidget(order)));
builder: (context) => PurchaseOrderDetailWidget(order)));
}
}
@ -231,7 +214,7 @@ class BarcodeScanHandler extends BarcodeHandler {
if (order is InvenTreeSalesOrder) {
OneContext().pop();
OneContext().push(MaterialPageRoute(
builder: (context) => SalesOrderDetailWidget(order)));
builder: (context) => SalesOrderDetailWidget(order)));
}
}
@ -251,7 +234,6 @@ class BarcodeScanHandler extends BarcodeHandler {
InvenTreeManufacturerPart.MODEL_TYPE,
];
if (InvenTreeAPI().supportsOrderBarcodes) {
validModels.add(InvenTreePurchaseOrder.MODEL_TYPE);
validModels.add(InvenTreeSalesOrder.MODEL_TYPE);
@ -275,7 +257,6 @@ class BarcodeScanHandler extends BarcodeHandler {
// A valid result has been found
if (pk > 0 && model.isNotEmpty) {
barcodeSuccessTone();
switch (model) {
@ -312,36 +293,27 @@ class BarcodeScanHandler extends BarcodeHandler {
// If we get here, we have not found a valid barcode result!
barcodeFailureTone();
showSnackIcon(
L10().barcodeUnknown,
success: false,
onAction: () {
if (hasContext()) {
OneContext().showDialog(
builder: (BuildContext context) =>
SimpleDialog(
title: Text(L10().unknownResponse),
children: <Widget>[
ListTile(
title: Text(L10().responseData),
subtitle: Text(data.toString()),
)
],
showSnackIcon(L10().barcodeUnknown, success: false, onAction: () {
if (hasContext()) {
OneContext().showDialog(
builder: (BuildContext context) => SimpleDialog(
title: Text(L10().unknownResponse),
children: <Widget>[
ListTile(
title: Text(L10().responseData),
subtitle: Text(data.toString()),
)
);
}
}
);
],
));
}
});
}
}
/*
* Barcode handler for finding a "unique" barcode (one that does not match an item in the database)
*/
class UniqueBarcodeHandler extends BarcodeHandler {
UniqueBarcodeHandler(this.callback, {this.overlayText = ""});
// Callback function when a "unique" barcode hash is found
@ -379,7 +351,6 @@ class UniqueBarcodeHandler extends BarcodeHandler {
success: false,
);
} else {
barcodeSuccessTone();
// Close the barcode scanner
@ -396,49 +367,43 @@ class UniqueBarcodeHandler extends BarcodeHandler {
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
await onBarcodeMatched(data);
}
}
SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state, String barcode, String model, int pk) {
SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state,
String barcode, String model, int pk) {
if (barcode.isEmpty) {
return SpeedDialChild(
label: L10().barcodeAssign,
child: Icon(Icons.barcode_reader),
onTap: () {
var handler = UniqueBarcodeHandler((String barcode) {
InvenTreeAPI().linkBarcode({
model: pk.toString(),
"barcode": barcode,
}).then((bool result) {
label: L10().barcodeAssign,
child: Icon(Icons.barcode_reader),
onTap: () {
var handler = UniqueBarcodeHandler((String barcode) {
InvenTreeAPI().linkBarcode({
model: pk.toString(),
"barcode": barcode,
}).then((bool result) {
showSnackIcon(
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
success: result);
state.refresh(context);
});
});
scanBarcode(context, handler: handler);
});
} else {
return SpeedDialChild(
child: Icon(Icons.barcode_reader),
label: L10().barcodeUnassign,
onTap: () {
InvenTreeAPI()
.unlinkBarcode({model: pk.toString()}).then((bool result) {
showSnackIcon(
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
success: result
result ? L10().requestSuccessful : L10().requestFailed,
success: result,
);
state.refresh(context);
});
});
scanBarcode(context, handler: handler);
}
);
} else {
return SpeedDialChild(
child: Icon(Icons.barcode_reader),
label: L10().barcodeUnassign,
onTap: () {
InvenTreeAPI().unlinkBarcode({
model: pk.toString()
}).then((bool result) {
showSnackIcon(
result ? L10().requestSuccessful : L10().requestFailed,
success: result,
);
state.refresh(context);
});
}
);
}
}

View File

@ -42,9 +42,8 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
String scanned_code = "";
final MobileScannerController controller = MobileScannerController(
autoZoom: true
);
final MobileScannerController controller =
MobileScannerController(autoZoom: true);
@override
void initState() {
@ -80,7 +79,6 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
@override
Future<void> pauseScan() async {
if (mounted) {
setState(() {
scanning_paused = true;
@ -90,7 +88,6 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
@override
Future<void> resumeScan() async {
controller.start();
if (mounted) {
@ -114,8 +111,7 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
setState(() {
multiple_barcodes = false;
});
}
else if (result.barcodes.length > 1) {
} else if (result.barcodes.length > 1) {
setState(() {
multiple_barcodes = true;
});
@ -175,18 +171,12 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
void onControllerCreated(CameraController? controller, Exception? error) {
if (error != null) {
sentryReportError(
"CameraBarcodeController.onControllerCreated",
error,
null
);
"CameraBarcodeController.onControllerCreated", error, null);
}
if (controller == null) {
showSnackIcon(
L10().cameraCreationError,
icon: TablerIcons.camera_x,
success: false
);
showSnackIcon(L10().cameraCreationError,
icon: TablerIcons.camera_x, success: false);
if (OneContext.hasContext) {
Navigator.pop(OneContext().context!);
@ -195,7 +185,6 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
}
Widget BarcodeOverlay(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;
final double width = screenSize.width;
final double height = screenSize.height;
@ -213,29 +202,25 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
overlayColor = COLOR_WARNING;
}
return Stack(
children: [
Center(
return Stack(children: [
Center(
child: Container(
width: D,
height: D,
decoration: BoxDecoration(
border: Border.all(
color: overlayColor,
width: 4,
),
),
)
)
]
);
width: D,
height: D,
decoration: BoxDecoration(
border: Border.all(
color: overlayColor,
width: 4,
),
),
))
]);
}
/*
* Build the barcode reader widget
*/
Widget BarcodeReader(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;
final double width = screenSize.width;
final double height = screenSize.height;
@ -248,10 +233,7 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
return BarcodeOverlay(context);
},
scanWindow: Rect.fromCenter(
center: Offset(width / 2, height / 2),
width: D,
height: D
),
center: Offset(width / 2, height / 2), width: D, height: D),
onDetect: (result) {
onScanSuccess(result);
},
@ -260,31 +242,21 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
Widget topCenterOverlay() {
return SafeArea(
child: Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.only(
left: 10,
right: 10,
top: 75,
bottom: 10
),
child: Text(
widget.handler.getOverlayText(context),
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold
)
)
)
)
);
child: Align(
alignment: Alignment.topCenter,
child: Padding(
padding:
EdgeInsets.only(left: 10, right: 10, top: 75, bottom: 10),
child: Text(widget.handler.getOverlayText(context),
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold)))));
}
Widget bottomCenterOverlay() {
String info_text = scanning_paused ? L10().barcodeScanPaused : L10().barcodeScanPause;
String info_text =
scanning_paused ? L10().barcodeScanPaused : L10().barcodeScanPause;
String text = scanned_code.isNotEmpty ? scanned_code : info_text;
@ -293,51 +265,39 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
}
return SafeArea(
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(
left: 10,
right: 10,
top: 10,
bottom: 75
),
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold
)
),
)
)
);
child: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding:
EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 75),
child: Text(text,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold)),
)));
}
Widget? buildActions(BuildContext context) {
List<SpeedDialChild> actions = [
SpeedDialChild(
child: Icon(flash_status ? TablerIcons.bulb_off : TablerIcons.bulb),
label: L10().toggleTorch,
onTap: () async {
controller.toggleTorch();
if (mounted) {
setState(() {
flash_status = !flash_status;
});
}
}
),
child: Icon(flash_status ? TablerIcons.bulb_off : TablerIcons.bulb),
label: L10().toggleTorch,
onTap: () async {
controller.toggleTorch();
if (mounted) {
setState(() {
flash_status = !flash_status;
});
}
}),
SpeedDialChild(
child: Icon(TablerIcons.camera),
label: L10().switchCamera,
onTap: () async {
controller.switchCamera();
}
)
child: Icon(TablerIcons.camera),
label: L10().switchCamera,
onTap: () async {
controller.switchCamera();
})
];
return SpeedDial(
@ -348,7 +308,6 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: COLOR_APP_BAR,
@ -368,9 +327,7 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
children: <Widget>[
Column(
children: [
Expanded(
child: BarcodeReader(context)
),
Expanded(child: BarcodeReader(context)),
],
),
topCenterOverlay(),
@ -380,5 +337,4 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
),
);
}
}

View File

@ -11,7 +11,6 @@ import "package:inventree/widget/progress.dart";
* which is used to process the scanned barcode.
*/
class InvenTreeBarcodeController extends StatefulWidget {
const InvenTreeBarcodeController(this.handler, {Key? key}) : super(key: key);
final BarcodeHandler handler;
@ -20,16 +19,16 @@ class InvenTreeBarcodeController extends StatefulWidget {
State<StatefulWidget> createState() => InvenTreeBarcodeControllerState();
}
/*
* Base state widget for the barcode controller.
* This defines the basic interface for the barcode controller.
*/
class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController> {
class InvenTreeBarcodeControllerState
extends State<InvenTreeBarcodeController> {
InvenTreeBarcodeControllerState() : super();
final GlobalKey barcodeControllerKey = GlobalKey(debugLabel: "barcodeController");
final GlobalKey barcodeControllerKey =
GlobalKey(debugLabel: "barcodeController");
// Internal state flag to test if we are currently processing a barcode
bool processingBarcode = false;
@ -40,7 +39,6 @@ class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController>
* Barcode data should be passed as a string
*/
Future<void> handleBarcodeData(String? data) async {
// Check that the data is valid, and this view is still mounted
if (!mounted || data == null || data.isEmpty) {
return;
@ -66,7 +64,8 @@ class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController>
return;
}
int delay = await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_DELAY, 500) as int;
int delay = await InvenTreeSettingsManager()
.getValue(INV_BARCODE_SCAN_DELAY, 500) as int;
Future.delayed(Duration(milliseconds: delay), () {
hideLoadingOverlay();
@ -99,5 +98,4 @@ class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController>
Widget build(BuildContext context) {
return Container();
}
}
}

View File

@ -1,4 +1,3 @@
import "package:flutter/material.dart";
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
@ -13,7 +12,6 @@ import "package:inventree/inventree/sentry.dart";
import "package:inventree/widget/dialogs.dart";
import "package:inventree/widget/snacks.dart";
/* Generic class which "handles" a barcode, by communicating with the InvenTree server,
* and handling match / unknown / error cases.
*
@ -21,7 +19,6 @@ import "package:inventree/widget/snacks.dart";
* based on the response returned from the InvenTree server
*/
class BarcodeHandler {
BarcodeHandler();
// Return the text to display on the barcode overlay
@ -60,21 +57,16 @@ class BarcodeHandler {
Future<void> processBarcode(String barcode,
{String url = "barcode/",
Map<String, dynamic> extra_data = const {}}) async {
debug("Scanned barcode data: '${barcode}'");
barcode = barcode.trim();
// Empty barcode is invalid
if (barcode.isEmpty) {
barcodeFailureTone();
showSnackIcon(
L10().barcodeError,
icon: TablerIcons.exclamation_circle,
success: false
);
showSnackIcon(L10().barcodeError,
icon: TablerIcons.exclamation_circle, success: false);
return;
}
@ -123,8 +115,7 @@ class BarcodeHandler {
"error": response.error,
"errorDetail": response.errorDetail,
"className": "${this}",
}
);
});
} else if (data.containsKey("success")) {
await onBarcodeMatched(data);
} else if ((response.statusCode >= 400) || data.containsKey("error")) {

View File

@ -20,7 +20,6 @@ import "package:inventree/widget/snacks.dart";
* - If location or quantity information wasn't provided, show a form to fill it in
*/
class POReceiveBarcodeHandler extends BarcodeHandler {
POReceiveBarcodeHandler({this.purchaseOrder, this.location, this.lineItem});
InvenTreePurchaseOrder? purchaseOrder;
@ -33,9 +32,9 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
@override
Future<void> processBarcode(String barcode,
{String url = "barcode/po-receive/",
Map<String, dynamic> extra_data = const {}}) async {
final bool confirm = await InvenTreeSettingsManager().getBool(INV_PO_CONFIRM_SCAN, true);
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,
@ -50,7 +49,6 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
@override
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
if (data.containsKey("lineitem") || data.containsKey("success")) {
barcodeSuccess(L10().receivedItem);
return;
@ -66,7 +64,8 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
}
final lineItemData = data["lineitem"] as Map<String, dynamic>;
if (!lineItemData.containsKey("pk") || !lineItemData.containsKey("purchase_order")) {
if (!lineItemData.containsKey("pk") ||
!lineItemData.containsKey("purchase_order")) {
barcodeFailureTone();
showSnackIcon(L10().missingData, success: false);
}
@ -79,7 +78,8 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
return;
}
InvenTreePOLineItem? lineItem = await InvenTreePOLineItem().get(lineItemId) as InvenTreePOLineItem?;
InvenTreePOLineItem? lineItem =
await InvenTreePOLineItem().get(lineItemId) as InvenTreePOLineItem?;
if (lineItem == null) {
barcodeFailureTone();
@ -89,7 +89,8 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
// Next, extract the "optional" fields
// Extract information from the returned server response
double? quantity = double.tryParse((lineItemData["quantity"] ?? "0").toString());
double? quantity =
double.tryParse((lineItemData["quantity"] ?? "0").toString());
int? destination = lineItemData["location"] as int?;
String? barcode = data["barcode_data"] as String?;
@ -98,33 +99,26 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
OneContext().pop();
}
await lineItem.receive(
OneContext().context!,
destination: destination,
quantity: quantity,
barcode: barcode,
onSuccess: () {
showSnackIcon(L10().receivedItem, success: true);
}
);
await lineItem.receive(OneContext().context!,
destination: destination,
quantity: quantity,
barcode: barcode, onSuccess: () {
showSnackIcon(L10().receivedItem, success: true);
});
}
@override
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
barcodeFailureTone();
showSnackIcon(
data["error"] as String? ?? L10().barcodeError,
success: false
);
showSnackIcon(data["error"] as String? ?? L10().barcodeError,
success: false);
}
}
/*
* Barcode handler to add a line item to a purchase order
*/
class POAllocateBarcodeHandler extends BarcodeHandler {
POAllocateBarcodeHandler({this.purchaseOrder});
InvenTreePurchaseOrder? purchaseOrder;
@ -133,11 +127,9 @@ class POAllocateBarcodeHandler extends BarcodeHandler {
String getOverlayText(BuildContext context) => L10().scanSupplierPart;
@override
Future<void> processBarcode(String barcode, {
String url = "barcode/po-allocate/",
Map<String, dynamic> extra_data = const {}}
) {
Future<void> processBarcode(String barcode,
{String url = "barcode/po-allocate/",
Map<String, dynamic> extra_data = const {}}) {
final po_extra_data = {
"purchase_order": purchaseOrder?.pk,
...extra_data,
@ -189,10 +181,9 @@ class POAllocateBarcodeHandler extends BarcodeHandler {
@override
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
print("onBarcodeUnhandled:");
print(data.toString());
super.onBarcodeUnhandled(data);
}
}
}

View File

@ -14,13 +14,11 @@ import "package:inventree/barcode/tones.dart";
import "package:inventree/widget/snacks.dart";
/*
* Barcode handler class for scanning a new part into a SalesOrder
*/
class SOAddItemBarcodeHandler extends BarcodeHandler {
SOAddItemBarcodeHandler({this.salesOrder});
InvenTreeSalesOrder? salesOrder;
@ -30,7 +28,6 @@ class SOAddItemBarcodeHandler extends BarcodeHandler {
@override
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
// Extract the part ID from the returned data
int part_id = -1;
@ -46,7 +43,6 @@ class SOAddItemBarcodeHandler extends BarcodeHandler {
var part = await InvenTreePart().get(part_id);
if (part is InvenTreePart) {
if (part.isSalable) {
// Dispose of the barcode scanner
if (OneContext.hasContext) {
@ -68,23 +64,18 @@ class SOAddItemBarcodeHandler extends BarcodeHandler {
L10().lineItemAdd,
fields: fields,
);
} else {
barcodeFailureTone();
showSnackIcon(L10().partNotSalable, success: false);
}
} else {
// Failed to fetch part
return onBarcodeUnknown(data);
}
}
}
class SOAllocateStockHandler extends BarcodeHandler {
SOAllocateStockHandler({this.salesOrder, this.lineItem, this.shipment});
InvenTreeSalesOrder? salesOrder;
@ -96,10 +87,8 @@ class SOAllocateStockHandler extends BarcodeHandler {
@override
Future<void> processBarcode(String barcode,
{
String url = "barcode/so-allocate/",
Map<String, dynamic> extra_data = const {}}) {
{String url = "barcode/so-allocate/",
Map<String, dynamic> extra_data = const {}}) {
final so_extra_data = {
"sales_order": salesOrder?.pk,
"shipment": shipment?.pk,
@ -121,8 +110,8 @@ class SOAllocateStockHandler extends BarcodeHandler {
@override
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
if (!data.containsKey("action_required") || !data.containsKey("line_item")) {
if (!data.containsKey("action_required") ||
!data.containsKey("line_item")) {
return super.onBarcodeUnhandled(data);
}
@ -147,30 +136,22 @@ class SOAllocateStockHandler extends BarcodeHandler {
fields["quantity"]?["value"] = data["quantity"];
fields["shipment"]?["value"] = data["shipment"];
fields["shipment"]?["filters"] = {
"order": salesOrder!.pk.toString()
};
fields["shipment"]?["filters"] = {"order": salesOrder!.pk.toString()};
final context = OneContext().context!;
launchApiForm(
context,
L10().allocateStock,
salesOrder!.allocate_url,
fields,
method: "POST",
icon: TablerIcons.transition_right,
onSuccess: (data) async {
showSnackIcon(L10().allocated, success: true);
context, L10().allocateStock, salesOrder!.allocate_url, fields,
method: "POST",
icon: TablerIcons.transition_right, 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
);
showSnackIcon(data["error"] as String? ?? L10().barcodeError,
success: false);
}
}
}

View File

@ -16,7 +16,6 @@ import "package:inventree/inventree/stock.dart";
import "package:inventree/widget/dialogs.dart";
import "package:inventree/widget/snacks.dart";
/*
* Generic class for scanning a StockLocation.
*
@ -24,20 +23,17 @@ import "package:inventree/widget/snacks.dart";
* - Runs a "callback" function if a valid StockLocation is found
*/
class BarcodeScanStockLocationHandler extends BarcodeHandler {
@override
String getOverlayText(BuildContext context) => L10().barcodeScanLocation;
@override
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
// We expect that the barcode points to a 'stocklocation'
if (data.containsKey("stocklocation")) {
int _loc = (data["stocklocation"]?["pk"] ?? -1) as int;
// A valid stock location!
if (_loc > 0) {
debug("Scanned stock location ${_loc}");
final bool result = await onLocationScanned(_loc);
@ -64,10 +60,8 @@ class BarcodeScanStockLocationHandler extends BarcodeHandler {
// Re-implement this for particular subclass
return false;
}
}
/*
* Generic class for scanning a StockItem
*
@ -75,7 +69,6 @@ class BarcodeScanStockLocationHandler extends BarcodeHandler {
* - Runs a "callback" function if a valid StockItem is found
*/
class BarcodeScanStockItemHandler extends BarcodeHandler {
@override
String getOverlayText(BuildContext context) => L10().barcodeScanItem;
@ -87,7 +80,6 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
// A valid stock location!
if (_item > 0) {
barcodeSuccessTone();
bool result = await onItemScanned(_item);
@ -115,7 +107,6 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
}
}
/*
* Barcode handler for scanning a provided StockItem into a scanned StockLocation.
*
@ -124,36 +115,28 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
* - The StockItem is transferred into the scanned location
*/
class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
StockItemScanIntoLocationHandler(this.item);
final InvenTreeStockItem item;
@override
Future<bool> onLocationScanned(int locationId) async {
final bool confirm = await InvenTreeSettingsManager().getBool(INV_STOCK_CONFIRM_SCAN, false);
final bool confirm =
await InvenTreeSettingsManager().getBool(INV_STOCK_CONFIRM_SCAN, false);
bool result = false;
if (confirm) {
Map<String, dynamic> fields = item.transferFields();
// Override location with scanned value
fields["location"]?["value"] = locationId;
launchApiForm(
OneContext().context!,
L10().transferStock,
InvenTreeStockItem.transferStockUrl(),
fields,
method: "POST",
icon: TablerIcons.transfer,
onSuccess: (data) async {
showSnackIcon(L10().stockItemUpdated, success: true);
}
);
launchApiForm(OneContext().context!, L10().transferStock,
InvenTreeStockItem.transferStockUrl(), fields,
method: "POST", icon: TablerIcons.transfer, onSuccess: (data) async {
showSnackIcon(L10().stockItemUpdated, success: true);
});
return true;
} else {
@ -171,7 +154,6 @@ class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
}
}
/*
* Barcode handler for scanning stock item(s) into the specified StockLocation.
*
@ -180,7 +162,6 @@ class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
* - The scanned StockItem is transferred into the provided StockLocation
*/
class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
StockLocationScanInItemsHandler(this.location);
final InvenTreeStockLocation location;
@ -190,14 +171,14 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
@override
Future<bool> onItemScanned(int itemId) async {
final InvenTreeStockItem? item = await InvenTreeStockItem().get(itemId) as InvenTreeStockItem?;
final bool confirm = await InvenTreeSettingsManager().getBool(INV_STOCK_CONFIRM_SCAN, false);
final InvenTreeStockItem? item =
await InvenTreeStockItem().get(itemId) as InvenTreeStockItem?;
final bool confirm =
await InvenTreeSettingsManager().getBool(INV_STOCK_CONFIRM_SCAN, false);
bool result = false;
if (item != null) {
// Item is already *in* the specified location
if (item.locationId == location.pk) {
barcodeFailureTone();
@ -210,27 +191,22 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
// Override location with provided location value
fields["location"]?["value"] = location.pk;
launchApiForm(
OneContext().context!,
L10().transferStock,
InvenTreeStockItem.transferStockUrl(),
fields,
launchApiForm(OneContext().context!, L10().transferStock,
InvenTreeStockItem.transferStockUrl(), fields,
method: "POST",
icon: TablerIcons.transfer,
onSuccess: (data) async {
showSnackIcon(L10().stockItemUpdated, success: true);
}
);
icon: TablerIcons.transfer, onSuccess: (data) async {
showSnackIcon(L10().stockItemUpdated, success: true);
});
return true;
} else {
result = await item.transferStock(location.pk);
showSnackIcon(
result ? L10().barcodeScanIntoLocationSuccess : L10().barcodeScanIntoLocationFailure,
success: result
);
result
? L10().barcodeScanIntoLocationSuccess
: L10().barcodeScanIntoLocationFailure,
success: result);
}
}
}
@ -240,7 +216,6 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
}
}
/*
* Barcode handler class for scanning a StockLocation into another StockLocation
*
@ -249,14 +224,12 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
* - The scanned StockLocation is set as the "parent" of the provided StockLocation
*/
class ScanParentLocationHandler extends BarcodeScanStockLocationHandler {
ScanParentLocationHandler(this.location);
final InvenTreeStockLocation location;
@override
Future<bool> onLocationScanned(int locationId) async {
final response = await location.update(
values: {
"parent": locationId.toString(),
@ -269,23 +242,19 @@ class ScanParentLocationHandler extends BarcodeScanStockLocationHandler {
case 201:
barcodeSuccess(L10().barcodeScanIntoLocationSuccess);
return true;
case 400: // Invalid parent location chosen
case 400: // Invalid parent location chosen
barcodeFailureTone();
showSnackIcon(L10().invalidStockLocation, success: false);
return false;
default:
barcodeFailureTone();
showSnackIcon(
L10().barcodeScanIntoLocationFailure,
success: false,
actionText: L10().details,
onAction: () {
showErrorDialog(
L10().barcodeError,
response: response,
);
}
);
showSnackIcon(L10().barcodeScanIntoLocationFailure,
success: false, actionText: L10().details, onAction: () {
showErrorDialog(
L10().barcodeError,
response: response,
);
});
return false;
}
}

View File

@ -5,19 +5,19 @@ import "package:inventree/preferences.dart";
* Play an audible 'success' alert to the user.
*/
Future<void> barcodeSuccessTone() async {
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
final bool en = await InvenTreeSettingsManager()
.getValue(INV_SOUNDS_BARCODE, true) as bool;
if (en) {
playAudioFile("sounds/barcode_scan.mp3");
}
}
Future <void> barcodeFailureTone() async {
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
Future<void> barcodeFailureTone() async {
final bool en = await InvenTreeSettingsManager()
.getValue(INV_SOUNDS_BARCODE, true) as bool;
if (en) {
playAudioFile("sounds/barcode_error.mp3");
}
}
}

View File

@ -1,4 +1,3 @@
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
@ -15,17 +14,14 @@ import "package:inventree/helpers.dart";
* intercepting barcode data which is entered as rapid keyboard presses
*/
class WedgeBarcodeController extends InvenTreeBarcodeController {
const WedgeBarcodeController(BarcodeHandler handler, {Key? key}) : super(handler, key: key);
const WedgeBarcodeController(BarcodeHandler handler, {Key? key})
: super(handler, key: key);
@override
State<StatefulWidget> createState() => _WedgeBarcodeControllerState();
}
class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
_WedgeBarcodeControllerState() : super();
bool canScan = true;
@ -40,7 +36,6 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
@override
Future<void> pauseScan() async {
if (mounted) {
setState(() {
canScan = false;
@ -50,7 +45,6 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
@override
Future<void> resumeScan() async {
if (mounted) {
setState(() {
canScan = true;
@ -60,7 +54,6 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
// Callback for a single key press / scan
void handleKeyEvent(KeyEvent event) {
if (!scanning) {
return;
}
@ -78,7 +71,8 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
DateTime now = DateTime.now();
// Throw away old characters
if (_lastScanTime == null || _lastScanTime!.isBefore(now.subtract(Duration(milliseconds: 250)))) {
if (_lastScanTime == null ||
_lastScanTime!.isBefore(now.subtract(Duration(milliseconds: 250)))) {
_scannedCharacters.clear();
}
@ -99,15 +93,14 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: COLOR_APP_BAR,
title: Text(L10().scanBarcode),
),
backgroundColor: Colors.black.withValues(alpha: 0.9),
body: Center(
child: Column(
appBar: AppBar(
backgroundColor: COLOR_APP_BAR,
title: Text(L10().scanBarcode),
),
backgroundColor: Colors.black.withValues(alpha: 0.9),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Spacer(flex: 5),
@ -118,8 +111,7 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
focusNode: _focusNode,
child: SizedBox(
child: CircularProgressIndicator(
color: scanning ? COLOR_ACTION : COLOR_PROGRESS
),
color: scanning ? COLOR_ACTION : COLOR_PROGRESS),
width: 64,
height: 64,
),
@ -136,18 +128,12 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
),
Spacer(flex: 5),
Padding(
child: Text(
widget.handler.getOverlayText(context),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white)
),
child: Text(widget.handler.getOverlayText(context),
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white)),
padding: EdgeInsets.all(20),
)
],
)
)
);
)));
}
}
}