2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-05-02 15:28:53 +00:00

Further fixes for adjustStock function

This commit is contained in:
Oliver 2022-01-09 07:59:13 +11:00
parent 5d0ffa059d
commit ed5764336f

View File

@ -458,8 +458,8 @@ class InvenTreeStockItem extends InvenTreeModel {
// TODO: Remove this function when we deprecate support for the old API // TODO: Remove this function when we deprecate support for the old API
Future<bool> adjustStock(BuildContext context, String endpoint, double q, {String? notes, int? location}) async { Future<bool> adjustStock(BuildContext context, String endpoint, double q, {String? notes, int? location}) async {
// Serialized stock cannot be adjusted // Serialized stock cannot be adjusted (unless it is a "transfer")
if (isSerialized()) { if (isSerialized() && location == null) {
return false; return false;
} }
@ -468,8 +468,6 @@ class InvenTreeStockItem extends InvenTreeModel {
return false; return false;
} }
print("Adjust stock: ${endpoint}");
Map<String, dynamic> data = {}; Map<String, dynamic> data = {};
// Note: Format of adjustment API was updated in API v14 // Note: Format of adjustment API was updated in API v14
@ -482,7 +480,6 @@ class InvenTreeStockItem extends InvenTreeModel {
"quantity": "${quantity}", "quantity": "${quantity}",
} }
], ],
"notes": notes ?? ""
}; };
} else { } else {
// Legacy (<= 14) API // Legacy (<= 14) API
@ -491,24 +488,22 @@ class InvenTreeStockItem extends InvenTreeModel {
"pk": "${pk}", "pk": "${pk}",
"quantity": "${quantity}", "quantity": "${quantity}",
}, },
"notes": notes ?? "",
}; };
} }
data["notes"] = notes ?? "";
if (location != null) { if (location != null) {
data["location"] = location; 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( var response = await api.post(
endpoint, endpoint,
body: { body: data,
"item": { expectedStatusCode: expected_response,
"pk": "${pk}",
"quantity": "${q}",
},
"notes": notes ?? "",
},
expectedStatusCode: 200
); );
return response.isValid(); return response.isValid();