diff --git a/assets/release_notes.md b/assets/release_notes.md index 84b57af6..348b74c2 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -1,6 +1,12 @@ ## InvenTree App Release Notes --- +### 0.9.1 - December 2022 +--- + +- Bug fixes for custom barcode actions +- Updated translations + ### 0.9.0 - December 2022 --- diff --git a/lib/api.dart b/lib/api.dart index f7d3a248..65ffbfdc 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -370,7 +370,7 @@ class InvenTreeAPI { response = await get("", expectedStatusCode: 200); if (!response.successful()) { - showStatusCodeError(apiUrl, response.statusCode); + showStatusCodeError(apiUrl, response.statusCode, details: response.data.toString()); return false; } @@ -1036,6 +1036,7 @@ class InvenTreeAPI { "method": method, } ); + return null; } } @@ -1091,13 +1092,11 @@ class InvenTreeAPI { } } else { + response.data = ignoreResponse ? {} : await responseToJson(url, _response) ?? {}; + // First check that the returned status code is what we expected if (statusCode != null && statusCode != _response.statusCode) { - showStatusCodeError(url, _response.statusCode); - } else if (ignoreResponse) { - response.data = {}; - } else { - response.data = await responseToJson(url, _response) ?? {}; + showStatusCodeError(url, _response.statusCode, details: response.data.toString()); } } } on HttpException catch (error) { diff --git a/lib/barcode.dart b/lib/barcode.dart index f3d8a272..16c98fc4 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -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 onBarcodeUnknown(Map 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 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); }); }, ); } -} \ No newline at end of file +} diff --git a/lib/widget/dialogs.dart b/lib/widget/dialogs.dart index 151958c2..2b6d511b 100644 --- a/lib/widget/dialogs.dart +++ b/lib/widget/dialogs.dart @@ -185,10 +185,10 @@ Future showServerError(String url, String title, String description) async /* * Displays an error indicating that the server returned an unexpected status code */ -Future showStatusCodeError(String url, int status) async { +Future showStatusCodeError(String url, int status, {String details=""}) async { String msg = L10().responseInvalid; - String extra = "${L10().statusCode}: ${status}"; + String extra = url + "\n" + "${L10().statusCode}: ${status}"; switch (status) { case 400: @@ -231,6 +231,11 @@ Future showStatusCodeError(String url, int status) async { break; } + if (details.isNotEmpty) { + extra += "\n"; + extra += details; + } + showServerError( url, msg, diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 3beefb62..1c2de589 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -456,7 +456,7 @@ class _LocationDisplayState extends RefreshableState { if (InvenTreeAPI().supportModernBarcodes) { tiles.add( - customBarcodeActionTile(context, location!.customBarcode, "stocklocation", location!.pk) + customBarcodeActionTile(context, this, location!.customBarcode, "stocklocation", location!.pk) ); } } diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 1a542af3..9c6b1141 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -698,7 +698,7 @@ class _PartDisplayState extends RefreshableState { if (InvenTreeAPI().supportModernBarcodes) { tiles.add( - customBarcodeActionTile(context, part.customBarcode, "part", part.pk) + customBarcodeActionTile(context, this, part.customBarcode, "part", part.pk) ); } diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index dcfd87d5..91f641ca 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -802,10 +802,23 @@ class _StockItemDisplayState extends RefreshableState { ) ); - if (InvenTreeAPI().supportModernBarcodes) { - tiles.add(customBarcodeActionTile(context, item.customBarcode, "stockitem", item.pk)); + if (InvenTreeAPI().supportModernBarcodes || item.customBarcode.isEmpty) { + 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) if (labels.isNotEmpty) { tiles.add(