From 6d796a2e329ab8fb65415f071e48434f5bcab346 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 15 Sep 2022 14:22:40 +1000 Subject: [PATCH] Barcode updates (#211) * Adds API function for unlinking a barcode * Show barcode unlink result * Update release notes and version number --- assets/release_notes.md | 1 + lib/api.dart | 21 ++++++++++++++++ lib/widget/stock_detail.dart | 48 +++++++++++++++++++++++++----------- pubspec.yaml | 2 +- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/assets/release_notes.md b/assets/release_notes.md index bc0ccd81..ef92d2d8 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -5,6 +5,7 @@ --- - Display list of assemblies which components are used in +- Fixes search input bug ### 0.8.2 - August 2022 --- diff --git a/lib/api.dart b/lib/api.dart index c2e9ce54..b32f4c4a 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -877,6 +877,27 @@ class InvenTreeAPI { ); } + /* + * Perform a request to unlink a custom barcode from a particular item + */ + Future unlinkBarcode(Map body) async { + + HttpClientRequest? request = await apiRequest("/barcode/unlink/", "POST"); + + if (request == null) { + return false; + } + + final response = await completeRequest( + request, + data: json.encode(body), + statusCode: 200, + ); + + return response.isValid() && response.statusCode == 200; + } + + HttpClient createClient(String url, {bool strictHttps = false}) { var client = HttpClient(); diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index bb3afcd1..9376e366 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -417,25 +417,43 @@ class _StockItemDisplayState extends RefreshableState { } + /* + * Unassign (remove) a barcode from a StockItem. + * + * Note that for API version < 76 this action is performed on the StockItem endpoint. + * For API version 76 or above, this uses the barcode "unlink" endpoint + */ Future _unassignBarcode(BuildContext context) async { - final response = await item.update(values: {"uid": ""}); + if (InvenTreeAPI().apiVersion < 76) { + final response = await item.update(values: {"uid": ""}); - switch (response.statusCode) { - case 200: - case 201: - showSnackIcon( - L10().stockItemUpdateSuccess, - success: true - ); - break; - default: - showSnackIcon( - L10().stockItemUpdateFailure, - success: false, - ); - break; + switch (response.statusCode) { + case 200: + case 201: + showSnackIcon( + L10().stockItemUpdateSuccess, + success: true + ); + break; + default: + showSnackIcon( + L10().stockItemUpdateFailure, + success: false, + ); + break; + } + } else { + final bool result = await InvenTreeAPI().unlinkBarcode({ + "stockitem": item.pk, + }); + + showSnackIcon( + result ? L10().stockItemUpdateSuccess : L10().stockItemUpdateFailure, + success: result, + ); } + refresh(context); } diff --git a/pubspec.yaml b/pubspec.yaml index b1fb090e..e84378a8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: inventree description: InvenTree stock management -version: 0.8.2+48 +version: 0.8.3+49 environment: sdk: ">=2.16.0 <3.0.0"