2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-17 04:35:26 +00:00

Adds code to requeest global setting from server

- Settings are individually cached for 5 minutes
- For now, use it for the purchase order reference prefix
This commit is contained in:
Oliver Walters
2022-05-09 21:41:34 +10:00
parent da3b668e8c
commit 059b69ce99
5 changed files with 61 additions and 7 deletions

View File

@ -47,6 +47,14 @@ class InvenTreeModel {
// Update whenever the model is loaded from the server
DateTime? lastReload;
bool reloadedWithin(Duration d) {
if (lastReload == null) {
return false;
} else {
return lastReload!.add(d).isAfter(DateTime.now());
}
}
// Override the endpoint URL for each subclass
String get URL => "";
@ -320,7 +328,7 @@ class InvenTreeModel {
}
// Return the detail view for the associated pk
Future<InvenTreeModel?> get(int pk, {Map<String, String> filters = const {}}) async {
Future<InvenTreeModel?> getModel(String pk, {Map<String, String> filters = const {}}) async {
var url = path.join(URL, pk.toString());
@ -367,6 +375,10 @@ class InvenTreeModel {
return createFromJson(response.asMap());
}
Future<InvenTreeModel?> get(int pk, {Map<String, String> filters = const {}}) async {
return getModel(pk.toString(), filters: filters);
}
Future<InvenTreeModel?> create(Map<String, dynamic> data) async {
if (data.containsKey("pk")) {