From ed5764336ff6ba8bbc4c7e0530dc520d0250c582 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 9 Jan 2022 07:59:13 +1100 Subject: [PATCH] Further fixes for adjustStock function --- lib/inventree/stock.dart | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 70375a9b..c49aef78 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -458,8 +458,8 @@ class InvenTreeStockItem extends InvenTreeModel { // TODO: Remove this function when we deprecate support for the old API Future adjustStock(BuildContext context, String endpoint, double q, {String? notes, int? location}) async { - // Serialized stock cannot be adjusted - if (isSerialized()) { + // Serialized stock cannot be adjusted (unless it is a "transfer") + if (isSerialized() && location == null) { return false; } @@ -468,8 +468,6 @@ class InvenTreeStockItem extends InvenTreeModel { return false; } - print("Adjust stock: ${endpoint}"); - Map data = {}; // Note: Format of adjustment API was updated in API v14 @@ -482,7 +480,6 @@ class InvenTreeStockItem extends InvenTreeModel { "quantity": "${quantity}", } ], - "notes": notes ?? "" }; } else { // Legacy (<= 14) API @@ -491,24 +488,22 @@ class InvenTreeStockItem extends InvenTreeModel { "pk": "${pk}", "quantity": "${quantity}", }, - "notes": notes ?? "", }; } + data["notes"] = notes ?? ""; + if (location != null) { data["location"] = location; } + // Expected API return code depends on server API version + final int expected_response = InvenTreeAPI().supportModernStockTransactions() ? 201 : 200; + var response = await api.post( endpoint, - body: { - "item": { - "pk": "${pk}", - "quantity": "${q}", - }, - "notes": notes ?? "", - }, - expectedStatusCode: 200 + body: data, + expectedStatusCode: expected_response, ); return response.isValid();