mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 02:05:29 +00:00
Refactor stock adjustment actions
- Handle timeout - Handle error
This commit is contained in:
@ -70,13 +70,11 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
double quantity = double.parse(_quantityController.text);
|
||||
_quantityController.clear();
|
||||
|
||||
// Await response to prevent the button from being pressed multiple times
|
||||
var response = await item.addStock(quantity, notes: _notesController.text);
|
||||
final bool result = await item.addStock(context, quantity, notes: _notesController.text);
|
||||
_notesController.clear();
|
||||
|
||||
_stockUpdateMessage(response);
|
||||
_stockUpdateMessage(result);
|
||||
|
||||
// TODO - Handle error cases
|
||||
refresh();
|
||||
}
|
||||
|
||||
@ -111,20 +109,27 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
void _stockUpdateMessage(bool result) {
|
||||
|
||||
showSnackIcon(
|
||||
refreshableKey,
|
||||
result ? "Stock item updated" : "Stock item updated failed",
|
||||
success: result
|
||||
);
|
||||
}
|
||||
|
||||
void _removeStock() async {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
double quantity = double.parse(_quantityController.text);
|
||||
_quantityController.clear();
|
||||
|
||||
var response = await item.removeStock(quantity, notes: _notesController.text);
|
||||
_notesController.clear();
|
||||
final bool result = await item.removeStock(context, quantity, notes: _notesController.text);
|
||||
|
||||
// TODO - Handle error cases
|
||||
_stockUpdateMessage(result);
|
||||
|
||||
refresh();
|
||||
|
||||
// TODO - Display a snackbar here indicating the action was successful (or otherwise)
|
||||
}
|
||||
|
||||
void _removeStockDialog() {
|
||||
@ -166,19 +171,16 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
double quantity = double.parse(_quantityController.text);
|
||||
_quantityController.clear();
|
||||
|
||||
var response = await item.countStock(quantity, notes: _notesController.text);
|
||||
_notesController.clear();
|
||||
final bool result = await item.countStock(context, quantity, notes: _notesController.text);
|
||||
|
||||
// TODO - Handle error cases, timeout, etc
|
||||
_stockUpdateMessage(result);
|
||||
|
||||
refresh();
|
||||
|
||||
// TODO - Display a snackbar here indicating the action was successful (or otherwise)
|
||||
}
|
||||
|
||||
void _countStockDialog() async {
|
||||
|
||||
_quantityController.text = item.quantity.toString();
|
||||
_quantityController.text = item.quantityString;
|
||||
_notesController.clear();
|
||||
|
||||
showFormDialog(context, I18N.of(context).countStock,
|
||||
@ -194,7 +196,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
fields: <Widget> [
|
||||
QuantityField(
|
||||
label: I18N.of(context).countStock,
|
||||
hint: "${item.quantity}",
|
||||
hint: "${item.quantityString}",
|
||||
controller: _quantityController,
|
||||
),
|
||||
TextFormField(
|
||||
@ -233,7 +235,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
|
||||
InvenTreeStockLocation selectedLocation;
|
||||
|
||||
_quantityController.text = "${item.quantity}";
|
||||
_quantityController.text = "${item.quantityString}";
|
||||
|
||||
showFormDialog(context, I18N.of(context).transferStock,
|
||||
key: _moveStockKey,
|
||||
@ -385,7 +387,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||
ListTile(
|
||||
title: Text(I18N.of(context).quantity),
|
||||
leading: FaIcon(FontAwesomeIcons.cubes),
|
||||
trailing: Text("${item.quantity}"),
|
||||
trailing: Text("${item.quantityString}"),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user