2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

Stock barcode fix (#232)

* API: Provide more info in error messages

* Fix support for legacy stock item custom barcodes

* Refresh display after assigning barcode

* Update release notes

* Fix for scanning unkown barcode

- Modern API returns slightly different data

* Fix for scanning unkown barcode

- Modern API returns slightly different data

* Update release notes
This commit is contained in:
Oliver
2022-12-11 23:41:21 +11:00
committed by GitHub
parent 27040024c0
commit d2b74e7684
7 changed files with 54 additions and 18 deletions

View File

@ -1,6 +1,7 @@
import "dart:io";
import "package:flutter/material.dart";
import "package:font_awesome_flutter/font_awesome_flutter.dart";
import "package:inventree/widget/refreshable_state.dart";
import "package:one_context/one_context.dart";
import "package:qr_code_scanner/qr_code_scanner.dart";
@ -569,16 +570,23 @@ class UniqueBarcodeHandler extends BarcodeHandler {
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
// If the barcode is unknown, we *can* assign it to the stock item!
if (!data.containsKey("hash")) {
if (!data.containsKey("hash") && !data.containsKey("barcode_hash")) {
showServerError(
"barcode/",
L10().missingData,
L10().barcodeMissingHash,
);
} else {
String hash = (data["hash"] ?? "") as String;
String barcode;
if (hash.isEmpty) {
if (InvenTreeAPI().supportModernBarcodes) {
barcode = (data["barcode_data"] ?? "") as String;
} else {
// Legacy barcode API
barcode = (data["hash"] ?? data["barcode_hash"] ?? "") as String;
}
if (barcode.isEmpty) {
barcodeFailureTone();
showSnackIcon(
@ -594,7 +602,7 @@ class UniqueBarcodeHandler extends BarcodeHandler {
OneContext().pop();
}
callback(hash);
callback(barcode);
}
}
}
@ -737,7 +745,7 @@ Future<void> scanQrCode(BuildContext context) async {
/*
* Construct a generic ListTile widget to link or un-link a custom barcode from a model.
*/
Widget customBarcodeActionTile(BuildContext context, String barcode, String model, int pk) {
Widget customBarcodeActionTile(BuildContext context, RefreshableState state, String barcode, String model, int pk) {
if (barcode.isEmpty) {
return ListTile(
@ -755,6 +763,8 @@ Widget customBarcodeActionTile(BuildContext context, String barcode, String mode
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
success: result
);
state.refresh(context);
});
});
@ -776,9 +786,12 @@ Widget customBarcodeActionTile(BuildContext context, String barcode, String mode
}).then((bool result) {
showSnackIcon(
result ? L10().requestSuccessful : L10().requestFailed,
success: result,
);
state.refresh(context);
});
},
);
}
}
}