From c4d8b5ce1c350d4b2e6a55d4e891857dae84fdd6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 18 Apr 2020 22:39:57 +1000 Subject: [PATCH] Stock transfer now works --- lib/inventree/stock.dart | 14 ++++++++++++++ lib/widget/stock_detail.dart | 23 +++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 5547266c..a4c829fb 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -218,6 +218,20 @@ class InvenTreeStockItem extends InvenTreeModel { }); } + Future transferStock(double q, int location, {String notes}) async { + + if ((q == null) || (q > quantity)) q = quantity; + + return api.post("/stock/transfer/", body: { + "item": { + "pk": "${pk}", + "quantity": "${q}", + }, + "location": "${location}", + "notes": notes ?? '', + }); + } + } diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index 6574d742..853318f0 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -184,7 +184,7 @@ class _StockItemDisplayState extends RefreshableState { var response = await item.countStock(quantity, notes: _notesController.text); _notesController.clear(); - // TODO - Handle error cases + // TODO - Handle error cases, timeout, etc refresh(); } @@ -218,8 +218,20 @@ class _StockItemDisplayState extends RefreshableState { } - void _transferStock(int location) { - // TODO + void _transferStock(int location) async { + Navigator.of(context).pop(); + + double quantity = double.parse(_quantityController.text); + String notes = _notesController.text; + + _quantityController.clear(); + _notesController.clear(); + + var response = await item.transferStock(quantity, location, notes: notes); + + // TODO - Error handling + refresh(); + } void _transferStockDialog() async { @@ -238,7 +250,7 @@ class _StockItemDisplayState extends RefreshableState { child: Text("Transfer"), onPressed: () { if (_moveStockKey.currentState.validate()) { - // TODO - Transfer! + _moveStockKey.currentState.save(); } }, ) @@ -280,6 +292,9 @@ class _StockItemDisplayState extends RefreshableState { selectedLocation = suggestion as InvenTreeStockLocation; _selectedController.text = selectedLocation.pathstring; }, + onSaved: (value) { + _transferStock(selectedLocation.pk); + }, itemBuilder: (context, suggestion) { var location = suggestion as InvenTreeStockLocation;