2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-13 10:45:29 +00:00

Remove support for legacy stock transfer API code

- Relies on modern API now
- Checks for error messages against hidden fields in stock items
This commit is contained in:
Oliver Walters
2022-05-22 15:59:19 +10:00
parent 55f713e3aa
commit 850c2b8c12
5 changed files with 189 additions and 353 deletions

View File

@ -295,76 +295,37 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}
Future <void> _addStock() async {
double quantity = double.parse(_quantityController.text);
_quantityController.clear();
final bool result = await item.addStock(context, quantity, notes: _notesController.text);
_notesController.clear();
_stockUpdateMessage(result);
refresh(context);
}
/*
* Launch a dialog to 'add' quantity to this StockItem
*/
Future <void> _addStockDialog() async {
// TODO: In future, deprecate support for older API
if (InvenTreeAPI().supportsModernStockTransactions) {
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": 0,
},
"notes": {},
};
launchApiForm(
context,
L10().addStock,
InvenTreeStockItem.addStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.plusCircle,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
return;
}
_quantityController.clear();
_notesController.clear();
showFormDialog( L10().addStock,
key: _addStockKey,
callback: () {
_addStock();
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
fields: <Widget> [
Text("Current stock: ${item.quantity}"),
QuantityField(
label: L10().addStock,
controller: _quantityController,
),
TextFormField(
decoration: InputDecoration(
labelText: L10().notes,
),
controller: _notesController,
)
],
"quantity": {
"parent": "items",
"nested": true,
"value": 0,
},
"notes": {},
};
launchApiForm(
context,
L10().addStock,
InvenTreeStockItem.addStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.plusCircle,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
}
@ -375,149 +336,68 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}
}
Future <void> _removeStock() async {
double quantity = double.parse(_quantityController.text);
_quantityController.clear();
final bool result = await item.removeStock(context, quantity, notes: _notesController.text);
_stockUpdateMessage(result);
refresh(context);
}
/*
* Launch a dialog to 'remove' quantity from this StockItem
*/
void _removeStockDialog() {
// TODO: In future, deprecate support for the older API
if (InvenTreeAPI().supportsModernStockTransactions) {
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": 0,
},
"notes": {},
};
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": 0,
},
"notes": {},
};
launchApiForm(
context,
L10().removeStock,
InvenTreeStockItem.removeStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.minusCircle,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
return;
}
_quantityController.clear();
_notesController.clear();
showFormDialog(L10().removeStock,
key: _removeStockKey,
callback: () {
_removeStock();
},
fields: <Widget>[
Text("Current stock: ${item.quantity}"),
QuantityField(
label: L10().removeStock,
controller: _quantityController,
max: item.quantity,
),
TextFormField(
decoration: InputDecoration(
labelText: L10().notes,
),
controller: _notesController,
),
],
launchApiForm(
context,
L10().removeStock,
InvenTreeStockItem.removeStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.minusCircle,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
}
Future <void> _countStock() async {
double quantity = double.parse(_quantityController.text);
_quantityController.clear();
final bool result = await item.countStock(context, quantity, notes: _notesController.text);
_stockUpdateMessage(result);
refresh(context);
}
Future <void> _countStockDialog() async {
// TODO: In future, deprecate support for older API
if (InvenTreeAPI().supportsModernStockTransactions) {
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": item.quantity,
},
"notes": {},
};
launchApiForm(
context,
L10().countStock,
InvenTreeStockItem.countStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.clipboardCheck,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
return;
}
_quantityController.text = item.quantity.toString();
_notesController.clear();
showFormDialog(L10().countStock,
key: _countStockKey,
callback: () {
_countStock();
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
acceptText: L10().count,
fields: <Widget> [
QuantityField(
label: L10().countStock,
hint: "${item.quantityString}",
controller: _quantityController,
),
TextFormField(
decoration: InputDecoration(
labelText: L10().notes,
),
controller: _notesController,
)
]
"quantity": {
"parent": "items",
"nested": true,
"value": item.quantity,
},
"notes": {},
};
launchApiForm(
context,
L10().countStock,
InvenTreeStockItem.countStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.clipboardCheck,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
}
@ -542,130 +422,43 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}
// TODO: Delete this function once support for old API is deprecated
Future <void> _transferStock(int locationId) async {
double quantity = double.tryParse(_quantityController.text) ?? item.quantity;
String notes = _notesController.text;
_quantityController.clear();
_notesController.clear();
var result = await item.transferStock(context, locationId, quantity: quantity, notes: notes);
refresh(context);
if (result) {
showSnackIcon(L10().stockItemTransferred, success: true);
}
}
/*
* Launches an API Form to transfer this stock item to a new location
*/
Future <void> _transferStockDialog(BuildContext context) async {
// TODO: In future, deprecate support for older API
if (InvenTreeAPI().supportsModernStockTransactions) {
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": item.quantity,
},
"location": {},
"notes": {},
};
Map<String, dynamic> fields = {
"pk": {
"parent": "items",
"nested": true,
"hidden": true,
"value": item.pk,
},
"quantity": {
"parent": "items",
"nested": true,
"value": item.quantity,
},
"location": {},
"notes": {},
};
launchApiForm(
context,
L10().transferStock,
InvenTreeStockItem.transferStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.dolly,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
return;
if (item.isSerialized()) {
// Prevent editing of 'quantity' field if the item is serialized
fields["quantity"]["hidden"] = true;
}
int? location_pk;
_quantityController.text = "${item.quantity}";
showFormDialog(L10().transferStock,
key: _moveStockKey,
callback: () {
var _pk = location_pk;
if (_pk != null) {
_transferStock(_pk);
}
},
fields: <Widget>[
QuantityField(
label: L10().quantity,
controller: _quantityController,
max: item.quantity,
),
DropdownSearch<dynamic>(
mode: Mode.BOTTOM_SHEET,
showSelectedItem: false,
autoFocusSearchBox: true,
selectedItem: null,
errorBuilder: (context, entry, exception) {
print("entry: $entry");
print(exception.toString());
return Text(
exception.toString(),
style: TextStyle(
fontSize: 10,
)
);
},
onFind: (String filter) async {
final results = await InvenTreeStockLocation().search(filter);
List<dynamic> items = [];
for (InvenTreeModel loc in results) {
if (loc is InvenTreeStockLocation) {
items.add(loc.jsondata);
}
}
return items;
},
label: L10().stockLocation,
hint: L10().searchLocation,
onChanged: null,
itemAsString: (dynamic location) {
return (location["pathstring"] ?? "") as String;
},
onSaved: (dynamic location) {
if (location == null) {
location_pk = null;
} else {
location_pk = location["pk"] as int;
}
},
isFilteredOnline: true,
showSearchBox: true,
),
],
launchApiForm(
context,
L10().transferStock,
InvenTreeStockItem.transferStockUrl(),
fields,
method: "POST",
icon: FontAwesomeIcons.dolly,
onSuccess: (data) async {
_stockUpdateMessage(true);
refresh(context);
}
);
}