mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-16 12:15:31 +00:00
Stock history fix (#320)
* Improves quantity parsing from * Add paginated history widget * Refactor stock history widget as a paginated widget * Allow paginated result list to handle results returned as list - Some API endpoints (older ones most likely) don't paginate results correctly * Fix code layout * Render user information in "history" widget (not quantity) * Hide filter button * Update release notes * remove unused import
This commit is contained in:
@ -575,10 +575,12 @@ class InvenTreeModel {
|
||||
// Construct the response
|
||||
InvenTreePageResponse page = InvenTreePageResponse();
|
||||
|
||||
var data = response.asMap();
|
||||
var dataMap = response.asMap();
|
||||
|
||||
if (data.containsKey("count") && data.containsKey("results")) {
|
||||
page.count = (data["count"] ?? 0) as int;
|
||||
// First attempt is to look for paginated data, returned as a map
|
||||
|
||||
if (dataMap.isNotEmpty && dataMap.containsKey("count") && dataMap.containsKey("results")) {
|
||||
page.count = (dataMap["count"] ?? 0) as int;
|
||||
|
||||
page.results = [];
|
||||
|
||||
@ -587,15 +589,28 @@ class InvenTreeModel {
|
||||
}
|
||||
|
||||
return page;
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Second attempt is to look for a list of data (not paginated)
|
||||
var dataList = response.asList();
|
||||
|
||||
if (dataList.isNotEmpty) {
|
||||
page.count = dataList.length;
|
||||
page.results = [];
|
||||
|
||||
for (var result in dataList) {
|
||||
page.addResult(createFromJson(result as Map<String, dynamic>));
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
// Finally, no results available
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return list of objects from the database, with optional filters
|
||||
Future<List<InvenTreeModel>> list({Map<String, String> filters = const {}}) async {
|
||||
|
||||
var params = defaultListFilters();
|
||||
|
||||
for (String key in filters.keys) {
|
||||
|
@ -23,9 +23,7 @@ class InvenTreeStockItemTestResult extends InvenTreeModel {
|
||||
@override
|
||||
Map<String, dynamic> formFields() {
|
||||
return {
|
||||
"stock_item": {
|
||||
"hidden": true
|
||||
},
|
||||
"stock_item": {"hidden": true},
|
||||
"test": {},
|
||||
"result": {},
|
||||
"value": {},
|
||||
@ -75,6 +73,7 @@ class InvenTreeStockItemHistory extends InvenTreeModel {
|
||||
// By default, order by decreasing date
|
||||
return {
|
||||
"ordering": "-date",
|
||||
"user_detail": "true",
|
||||
};
|
||||
}
|
||||
|
||||
@ -98,21 +97,31 @@ class InvenTreeStockItemHistory extends InvenTreeModel {
|
||||
|
||||
String get label => (jsondata["label"] ?? "") as String;
|
||||
|
||||
String get quantityString {
|
||||
Map<String, dynamic> deltas = (jsondata["deltas"] ?? {}) as Map<String, dynamic>;
|
||||
// Return the "deltas" associated with this historical object
|
||||
Map<String, dynamic> get deltas {
|
||||
if (jsondata.containsKey("deltas")) {
|
||||
return jsondata["deltas"] as Map<String, dynamic>;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
// Serial number takes priority here
|
||||
if (deltas.containsKey("serial")) {
|
||||
var serial = (deltas["serial"] ?? "").toString();
|
||||
return "# ${serial}";
|
||||
} else if (deltas.containsKey("quantity")) {
|
||||
double q = (deltas["quantity"] ?? 0) as double;
|
||||
// Return the quantity string for this historical object
|
||||
String get quantityString {
|
||||
var _deltas = deltas;
|
||||
|
||||
if (_deltas.containsKey("quantity")) {
|
||||
double q = double.tryParse(_deltas["quantity"].toString()) ?? 0;
|
||||
|
||||
return simpleNumberString(q);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
String get userString {
|
||||
return (jsondata["user_detail"]?["username"] ?? "") as String;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user