mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +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:
parent
27040024c0
commit
d2b74e7684
@ -1,6 +1,12 @@
|
|||||||
## InvenTree App Release Notes
|
## InvenTree App Release Notes
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 0.9.1 - December 2022
|
||||||
|
---
|
||||||
|
|
||||||
|
- Bug fixes for custom barcode actions
|
||||||
|
- Updated translations
|
||||||
|
|
||||||
### 0.9.0 - December 2022
|
### 0.9.0 - December 2022
|
||||||
---
|
---
|
||||||
|
|
||||||
|
11
lib/api.dart
11
lib/api.dart
@ -370,7 +370,7 @@ class InvenTreeAPI {
|
|||||||
response = await get("", expectedStatusCode: 200);
|
response = await get("", expectedStatusCode: 200);
|
||||||
|
|
||||||
if (!response.successful()) {
|
if (!response.successful()) {
|
||||||
showStatusCodeError(apiUrl, response.statusCode);
|
showStatusCodeError(apiUrl, response.statusCode, details: response.data.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1036,6 +1036,7 @@ class InvenTreeAPI {
|
|||||||
"method": method,
|
"method": method,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1091,13 +1092,11 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
response.data = ignoreResponse ? {} : await responseToJson(url, _response) ?? {};
|
||||||
|
|
||||||
// First check that the returned status code is what we expected
|
// First check that the returned status code is what we expected
|
||||||
if (statusCode != null && statusCode != _response.statusCode) {
|
if (statusCode != null && statusCode != _response.statusCode) {
|
||||||
showStatusCodeError(url, _response.statusCode);
|
showStatusCodeError(url, _response.statusCode, details: response.data.toString());
|
||||||
} else if (ignoreResponse) {
|
|
||||||
response.data = {};
|
|
||||||
} else {
|
|
||||||
response.data = await responseToJson(url, _response) ?? {};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} on HttpException catch (error) {
|
} on HttpException catch (error) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import "dart:io";
|
import "dart:io";
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:font_awesome_flutter/font_awesome_flutter.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:one_context/one_context.dart";
|
||||||
import "package:qr_code_scanner/qr_code_scanner.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 {
|
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
||||||
// If the barcode is unknown, we *can* assign it to the stock item!
|
// 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(
|
showServerError(
|
||||||
"barcode/",
|
"barcode/",
|
||||||
L10().missingData,
|
L10().missingData,
|
||||||
L10().barcodeMissingHash,
|
L10().barcodeMissingHash,
|
||||||
);
|
);
|
||||||
} else {
|
} 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();
|
barcodeFailureTone();
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
@ -594,7 +602,7 @@ class UniqueBarcodeHandler extends BarcodeHandler {
|
|||||||
OneContext().pop();
|
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.
|
* 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) {
|
if (barcode.isEmpty) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@ -755,6 +763,8 @@ Widget customBarcodeActionTile(BuildContext context, String barcode, String mode
|
|||||||
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
|
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
|
||||||
success: result
|
success: result
|
||||||
);
|
);
|
||||||
|
|
||||||
|
state.refresh(context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -776,7 +786,10 @@ Widget customBarcodeActionTile(BuildContext context, String barcode, String mode
|
|||||||
}).then((bool result) {
|
}).then((bool result) {
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
result ? L10().requestSuccessful : L10().requestFailed,
|
result ? L10().requestSuccessful : L10().requestFailed,
|
||||||
|
success: result,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
state.refresh(context);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -185,10 +185,10 @@ Future<void> showServerError(String url, String title, String description) async
|
|||||||
/*
|
/*
|
||||||
* Displays an error indicating that the server returned an unexpected status code
|
* Displays an error indicating that the server returned an unexpected status code
|
||||||
*/
|
*/
|
||||||
Future<void> showStatusCodeError(String url, int status) async {
|
Future<void> showStatusCodeError(String url, int status, {String details=""}) async {
|
||||||
|
|
||||||
String msg = L10().responseInvalid;
|
String msg = L10().responseInvalid;
|
||||||
String extra = "${L10().statusCode}: ${status}";
|
String extra = url + "\n" + "${L10().statusCode}: ${status}";
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 400:
|
case 400:
|
||||||
@ -231,6 +231,11 @@ Future<void> showStatusCodeError(String url, int status) async {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (details.isNotEmpty) {
|
||||||
|
extra += "\n";
|
||||||
|
extra += details;
|
||||||
|
}
|
||||||
|
|
||||||
showServerError(
|
showServerError(
|
||||||
url,
|
url,
|
||||||
msg,
|
msg,
|
||||||
|
@ -456,7 +456,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
|
|
||||||
if (InvenTreeAPI().supportModernBarcodes) {
|
if (InvenTreeAPI().supportModernBarcodes) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
customBarcodeActionTile(context, location!.customBarcode, "stocklocation", location!.pk)
|
customBarcodeActionTile(context, this, location!.customBarcode, "stocklocation", location!.pk)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -698,7 +698,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
|
|
||||||
if (InvenTreeAPI().supportModernBarcodes) {
|
if (InvenTreeAPI().supportModernBarcodes) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
customBarcodeActionTile(context, part.customBarcode, "part", part.pk)
|
customBarcodeActionTile(context, this, part.customBarcode, "part", part.pk)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -802,9 +802,22 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (InvenTreeAPI().supportModernBarcodes) {
|
if (InvenTreeAPI().supportModernBarcodes || item.customBarcode.isEmpty) {
|
||||||
tiles.add(customBarcodeActionTile(context, item.customBarcode, "stockitem", item.pk));
|
tiles.add(customBarcodeActionTile(context, this, item.customBarcode, "stockitem", item.pk));
|
||||||
|
} else {
|
||||||
|
// Note: Custom legacy barcodes (only for StockItem model) are handled differently
|
||||||
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
|
title: Text(L10().barcodeUnassign),
|
||||||
|
leading: Icon(Icons.qr_code, color: COLOR_CLICK),
|
||||||
|
onTap: () async {
|
||||||
|
await item.update(values: {"uid": ""});
|
||||||
|
refresh(context);
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Print label (if label printing plugins exist)
|
// Print label (if label printing plugins exist)
|
||||||
if (labels.isNotEmpty) {
|
if (labels.isNotEmpty) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user