2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Add notes field to stock actions

This commit is contained in:
Oliver Walters 2020-04-10 00:10:39 +10:00
parent b10931f3b6
commit 5a9dead4e6
4 changed files with 39 additions and 14 deletions

View File

@ -277,7 +277,7 @@ class InvenTreeAPI {
var _url = makeApiUrl(url); var _url = makeApiUrl(url);
var _headers = jsonHeaders(); var _headers = jsonHeaders();
print("POST: " + _url); print("POST: ${_url} -> ${body.toString()}");
var data = jsonEncode(body); var data = jsonEncode(body);

View File

@ -85,8 +85,6 @@ class InvenTreeModel {
*/ */
Future<bool> reload() async { Future<bool> reload() async {
print("Reloading data from $url");
var response = await api.get(url, params: defaultGetFilters()); var response = await api.get(url, params: defaultGetFilters());
if (response.statusCode != 200) { if (response.statusCode != 200) {

View File

@ -157,7 +157,7 @@ class InvenTreeStockItem extends InvenTreeModel {
return item; return item;
} }
Future<http.Response> countStock(double quan) async { Future<http.Response> countStock(double quan, {String notes}) async {
// Cannot 'count' a serialized StockItem // Cannot 'count' a serialized StockItem
if (isSerialized()) { if (isSerialized()) {
@ -172,12 +172,13 @@ class InvenTreeStockItem extends InvenTreeModel {
return api.post("/stock/count/", body: { return api.post("/stock/count/", body: {
"item": { "item": {
"pk": "${pk}", "pk": "${pk}",
"quantity": "${quan}" "quantity": "${quan}",
} },
"notes": notes ?? '',
}); });
} }
Future<http.Response> addStock(double quan) async { Future<http.Response> addStock(double quan, {String notes}) async {
if (isSerialized() || quan <= 0) return null; if (isSerialized() || quan <= 0) return null;
@ -185,11 +186,12 @@ class InvenTreeStockItem extends InvenTreeModel {
"item": { "item": {
"pk": "${pk}", "pk": "${pk}",
"quantity": "${quan}", "quantity": "${quan}",
} },
"notes": notes ?? '',
}); });
} }
Future<http.Response> removeStock(double quan) async { Future<http.Response> removeStock(double quan, {String notes}) async {
if (isSerialized() || quan <= 0) return null; if (isSerialized() || quan <= 0) return null;
@ -197,7 +199,8 @@ class InvenTreeStockItem extends InvenTreeModel {
"item": { "item": {
"pk": "${pk}", "pk": "${pk}",
"quantity": "${quan}", "quantity": "${quan}",
} },
"notes": notes ?? '',
}); });
} }

View File

@ -27,6 +27,9 @@ class StockDetailWidget extends StatefulWidget {
class _StockItemDisplayState extends State<StockDetailWidget> { class _StockItemDisplayState extends State<StockDetailWidget> {
// Single TextEditingController which can be shared between dialogs
final TextEditingController _notesController = TextEditingController();
final _addStockKey = GlobalKey<FormState>(); final _addStockKey = GlobalKey<FormState>();
final _removeStockKey = GlobalKey<FormState>(); final _removeStockKey = GlobalKey<FormState>();
final _countStockKey = GlobalKey<FormState>(); final _countStockKey = GlobalKey<FormState>();
@ -47,7 +50,8 @@ class _StockItemDisplayState extends State<StockDetailWidget> {
Navigator.of(context).pop(); Navigator.of(context).pop();
// Await response to prevent the button from being pressed multiple times // 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 // TODO - Handle error cases
@ -95,6 +99,12 @@ class _StockItemDisplayState extends State<StockDetailWidget> {
return null; return null;
}, },
), ),
TextFormField(
decoration: InputDecoration(
labelText: "Notes",
),
controller: _notesController,
)
], ],
) )
), ),
@ -107,7 +117,8 @@ class _StockItemDisplayState extends State<StockDetailWidget> {
void _removeStock(double quantity) async { void _removeStock(double quantity) async {
Navigator.of(context).pop(); 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 // TODO - Handle error cases
@ -156,7 +167,13 @@ class _StockItemDisplayState extends State<StockDetailWidget> {
return null; return null;
}, },
) ),
TextFormField(
decoration: InputDecoration(
labelText: "Notes",
),
controller: _notesController,
),
], ],
) )
), ),
@ -169,7 +186,8 @@ class _StockItemDisplayState extends State<StockDetailWidget> {
Navigator.of(context).pop(); 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 // TODO - Handle error cases
@ -217,6 +235,12 @@ class _StockItemDisplayState extends State<StockDetailWidget> {
return null; return null;
}, },
),
TextFormField(
decoration: InputDecoration(
labelText: "Notes",
),
controller: _notesController,
) )
], ],
) )