From 5a9dead4e6836709ffed7c76eeb4840f6566dd4b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 10 Apr 2020 00:10:39 +1000 Subject: [PATCH] Add notes field to stock actions --- lib/api.dart | 2 +- lib/inventree/model.dart | 2 -- lib/inventree/stock.dart | 17 ++++++++++------- lib/widget/stock_detail.dart | 32 ++++++++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index c2872b6b..6d272520 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -277,7 +277,7 @@ class InvenTreeAPI { var _url = makeApiUrl(url); var _headers = jsonHeaders(); - print("POST: " + _url); + print("POST: ${_url} -> ${body.toString()}"); var data = jsonEncode(body); diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index c47f19b7..a501ce7a 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -85,8 +85,6 @@ class InvenTreeModel { */ Future reload() async { - print("Reloading data from $url"); - var response = await api.get(url, params: defaultGetFilters()); if (response.statusCode != 200) { diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index baaf4151..e8cfcf22 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -157,7 +157,7 @@ class InvenTreeStockItem extends InvenTreeModel { return item; } - Future countStock(double quan) async { + Future countStock(double quan, {String notes}) async { // Cannot 'count' a serialized StockItem if (isSerialized()) { @@ -172,12 +172,13 @@ class InvenTreeStockItem extends InvenTreeModel { return api.post("/stock/count/", body: { "item": { "pk": "${pk}", - "quantity": "${quan}" - } + "quantity": "${quan}", + }, + "notes": notes ?? '', }); } - Future addStock(double quan) async { + Future addStock(double quan, {String notes}) async { if (isSerialized() || quan <= 0) return null; @@ -185,11 +186,12 @@ class InvenTreeStockItem extends InvenTreeModel { "item": { "pk": "${pk}", "quantity": "${quan}", - } + }, + "notes": notes ?? '', }); } - Future removeStock(double quan) async { + Future removeStock(double quan, {String notes}) async { if (isSerialized() || quan <= 0) return null; @@ -197,7 +199,8 @@ class InvenTreeStockItem extends InvenTreeModel { "item": { "pk": "${pk}", "quantity": "${quan}", - } + }, + "notes": notes ?? '', }); } diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index de365939..aabd6c7c 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -27,6 +27,9 @@ class StockDetailWidget extends StatefulWidget { class _StockItemDisplayState extends State { + // Single TextEditingController which can be shared between dialogs + final TextEditingController _notesController = TextEditingController(); + final _addStockKey = GlobalKey(); final _removeStockKey = GlobalKey(); final _countStockKey = GlobalKey(); @@ -47,7 +50,8 @@ class _StockItemDisplayState extends State { Navigator.of(context).pop(); // Await response to prevent the button from being pressed multiple times - var response = await item.addStock(quantity); + var response = await item.addStock(quantity, notes: _notesController.text); + _notesController.clear(); // TODO - Handle error cases @@ -95,6 +99,12 @@ class _StockItemDisplayState extends State { return null; }, ), + TextFormField( + decoration: InputDecoration( + labelText: "Notes", + ), + controller: _notesController, + ) ], ) ), @@ -107,7 +117,8 @@ class _StockItemDisplayState extends State { void _removeStock(double quantity) async { Navigator.of(context).pop(); - var response = await item.removeStock(quantity); + var response = await item.removeStock(quantity, notes: _notesController.text); + _notesController.clear(); // TODO - Handle error cases @@ -156,7 +167,13 @@ class _StockItemDisplayState extends State { return null; }, - ) + ), + TextFormField( + decoration: InputDecoration( + labelText: "Notes", + ), + controller: _notesController, + ), ], ) ), @@ -169,7 +186,8 @@ class _StockItemDisplayState extends State { Navigator.of(context).pop(); - var response = await item.countStock(quantity); + var response = await item.countStock(quantity, notes: _notesController.text); + _notesController.clear(); // TODO - Handle error cases @@ -217,6 +235,12 @@ class _StockItemDisplayState extends State { return null; }, + ), + TextFormField( + decoration: InputDecoration( + labelText: "Notes", + ), + controller: _notesController, ) ], )