From 80f7694abb73e4646c395db02af9d4dad7267ea1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 9 Apr 2020 23:21:53 +1000 Subject: [PATCH] Function to count stock item --- lib/inventree/stock.dart | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 9679ab6d..50ff635a 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -157,6 +157,26 @@ class InvenTreeStockItem extends InvenTreeModel { return item; } + Future countStock(double quan) async { + + // Cannot 'count' a serialized StockItem + if (isSerialized()) { + return null; + } + + // Cannot count negative stock + if (quan < 0) { + return null; + } + + return api.post("/stock/count/", body: { + "item": { + "pk": "${pk}", + "quantity": "${quan}" + } + }); + } + Future addStock(double quan) async { // Cannot add stock to a serialized StockItem @@ -169,14 +189,12 @@ class InvenTreeStockItem extends InvenTreeModel { return null; } - Map data = { + return api.post("/stock/add/", body: { "item": { "pk": "${pk}", "quantity": "${quan}", } - }; - - return api.post("/stock/add/", body: data); + }); } }