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:
Oliver 2023-04-18 22:46:08 +10:00 committed by GitHub
parent 01a45568a0
commit d926686a89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 116 additions and 63 deletions

View file

@ -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) {