mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 05:15:42 +00:00 
			
		
		
		
	Test result fixes (#564)
* Fix association of test results to templates * Fixes * Remove unused vars
This commit is contained in:
		| @@ -316,6 +316,10 @@ class InvenTreeAPI { | ||||
|   // Does the server support allocating stock to sales order using barcodes? | ||||
|   bool get supportsBarcodeSOAllocateEndpoint => isConnected() && apiVersion >= 160; | ||||
|  | ||||
|   // Does the server support the "modern" test results API | ||||
|   // Ref: https://github.com/inventree/InvenTree/pull/6430/ | ||||
|   bool get supportsModernTestResults => isConnected() && apiVersion >= 169; | ||||
|  | ||||
|   // Does the server support "null" top-level filtering for PartCategory and StockLocation endpoints? | ||||
|   bool get supportsNullTopLevelFiltering => isConnected() && apiVersion < 174; | ||||
|  | ||||
|   | ||||
| @@ -657,7 +657,13 @@ class APIFormField { | ||||
|           ) : null, | ||||
|           leading: extended ? InvenTreeAPI().getThumbnail(part.thumbnail) : null, | ||||
|         ); | ||||
|       case "parttesttemplate": | ||||
|           var template = InvenTreePartTestTemplate.fromJson(data); | ||||
|  | ||||
|           return ListTile( | ||||
|             title: Text(template.testName), | ||||
|             subtitle: Text(template.description), | ||||
|           ); | ||||
|       case "supplierpart": | ||||
|         var part = InvenTreeSupplierPart.fromJson(data); | ||||
|  | ||||
|   | ||||
| @@ -97,7 +97,6 @@ class InvenTreeModel { | ||||
|     if (data.containsKey(key)) { | ||||
|       return data[key]; | ||||
|     } else { | ||||
|       debug("JSON data does not contain key '$key' (subKey '${subKey}')"); | ||||
|       return backup; | ||||
|     } | ||||
|   } | ||||
| @@ -427,13 +426,17 @@ class InvenTreeModel { | ||||
|     } | ||||
| } | ||||
|  | ||||
|   Map<String, String> defaultListFilters() { | ||||
|   Map<String, String> defaultFilters() { | ||||
|     return {}; | ||||
|   } | ||||
|  | ||||
|   Map<String, String> defaultListFilters() { | ||||
|     return defaultFilters(); | ||||
|   } | ||||
|  | ||||
|   // A map of "default" headers to use when performing a GET request | ||||
|   Map<String, String> defaultGetFilters() { | ||||
|     return {}; | ||||
|     return defaultFilters(); | ||||
|   } | ||||
|  | ||||
|   /* | ||||
|   | ||||
| @@ -27,19 +27,43 @@ class InvenTreeStockItemTestResult extends InvenTreeModel { | ||||
|   List<String> get rolesRequired => ["stock"]; | ||||
|  | ||||
|   @override | ||||
|   Map<String, Map<String, dynamic>> formFields() { | ||||
|   Map<String, String> defaultFilters() { | ||||
|     return { | ||||
|       "user_detail": "true", | ||||
|       "template_detail": "true", | ||||
|     }; | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   Map<String, Map<String, dynamic>> formFields() { | ||||
|  | ||||
|     Map<String, Map<String, dynamic>> fields = { | ||||
|       "stock_item": {"hidden": true}, | ||||
|       "test": {}, | ||||
|       "template": { | ||||
|         "filters": { | ||||
|           "enabled": "true", | ||||
|         } | ||||
|       }, | ||||
|       "result": {}, | ||||
|       "value": {}, | ||||
|       "notes": {}, | ||||
|       "attachment": {}, | ||||
|     }; | ||||
|  | ||||
|     if (InvenTreeAPI().supportsModernTestResults) { | ||||
|       fields.remove("test"); | ||||
|     } else { | ||||
|       fields.remove("template"); | ||||
|     } | ||||
|  | ||||
|     return fields; | ||||
|   } | ||||
|  | ||||
|   String get key => getString("key"); | ||||
|  | ||||
|   int get templateId => getInt("template"); | ||||
|  | ||||
|   String get testName => getString("test"); | ||||
|  | ||||
|   bool get result => getBool("result"); | ||||
| @@ -48,6 +72,8 @@ class InvenTreeStockItemTestResult extends InvenTreeModel { | ||||
|    | ||||
|   String get attachment => getString("attachment"); | ||||
|  | ||||
|   String get username => getString("username", subKey: "user_detail"); | ||||
|  | ||||
|   String get date => getString("date"); | ||||
|    | ||||
|   @override | ||||
| @@ -256,6 +282,7 @@ class InvenTreeStockItem extends InvenTreeModel { | ||||
|     await InvenTreePartTestTemplate().list( | ||||
|       filters: { | ||||
|         "part": "${partId}", | ||||
|         "enabled": "true", | ||||
|       }, | ||||
|     ).then((var templates) { | ||||
|       testTemplates.clear(); | ||||
|   | ||||
| @@ -62,12 +62,19 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes | ||||
|  | ||||
|   final InvenTreeStockItem item; | ||||
|  | ||||
|   Future <void> addTestResult(BuildContext context, {String name = "", bool nameIsEditable = true, bool result = false, String value = "", bool valueRequired = false, bool attachmentRequired = false}) async  { | ||||
|   Future <void> addTestResult(BuildContext context, {int templateId = 0, String name = "", bool nameIsEditable = true, bool result = false, String value = "", bool valueRequired = false, bool attachmentRequired = false}) async  { | ||||
|  | ||||
|     Map<String, Map<String, dynamic>> fields = InvenTreeStockItemTestResult().formFields(); | ||||
|  | ||||
|     // Add additional filters | ||||
|     fields["template"]?["filters"]?["part"] = "${item.partId}"; | ||||
|  | ||||
|     InvenTreeStockItemTestResult().createForm( | ||||
|       context, | ||||
|       L10().testResultAdd, | ||||
|       fields: fields, | ||||
|       data: { | ||||
|         "template": "${templateId}", | ||||
|         "stock_item": "${item.pk}", | ||||
|         "test": "${name}", | ||||
|       }, | ||||
| @@ -98,10 +105,11 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes | ||||
|  | ||||
|         // Check against templates | ||||
|         if (outputs[ii] is InvenTreePartTestTemplate) { | ||||
|           var t = outputs[ii] as InvenTreePartTestTemplate; | ||||
|           var template = outputs[ii] as InvenTreePartTestTemplate; | ||||
|  | ||||
|           if (result.key == t.key) { | ||||
|             t.results.add(result); | ||||
|           // Match the result to a template | ||||
|           if (result.templateId == template.pk || result.key == template.key) { | ||||
|             template.results.add(result); | ||||
|             match = true; | ||||
|             break; | ||||
|           } | ||||
| @@ -168,9 +176,10 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes | ||||
|       bool _hasResult = false; | ||||
|       bool _required = false; | ||||
|       String _test = ""; | ||||
|       int _templateId = 0; | ||||
|       bool _result = false; | ||||
|       String _value = ""; | ||||
|       String _notes = ""; | ||||
|       String _date = ""; | ||||
|  | ||||
|       Widget _icon = Icon(TablerIcons.help_circle, color: Colors.lightBlue); | ||||
|       bool _valueRequired = false; | ||||
| @@ -179,18 +188,20 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes | ||||
|       if (item is InvenTreePartTestTemplate) { | ||||
|         _result = item.passFailStatus(); | ||||
|         _test = item.testName; | ||||
|         _templateId = item.pk; | ||||
|         _required = item.required; | ||||
|         _value = item.latestResult()?.value ?? L10().noResults; | ||||
|         _valueRequired = item.requiresValue; | ||||
|         _attachmentRequired = item.requiresAttachment; | ||||
|         _notes = item.latestResult()?.notes ?? item.description; | ||||
|         _date = item.latestResult()?.date ?? ""; | ||||
|         _hasResult = item.latestResult() != null; | ||||
|       } else if (item is InvenTreeStockItemTestResult) { | ||||
|         _result = item.result; | ||||
|         _test = item.testName; | ||||
|         _templateId = item.templateId; | ||||
|         _date = item.date; | ||||
|         _required = false; | ||||
|         _value = item.value; | ||||
|         _notes = item.notes; | ||||
|         _hasResult = true; | ||||
|       } | ||||
|  | ||||
| @@ -207,18 +218,21 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes | ||||
|           fontWeight: _required ? FontWeight.bold : FontWeight.normal, | ||||
|           fontStyle: _hasResult ? FontStyle.normal : FontStyle.italic | ||||
|         )), | ||||
|         subtitle: Text(_notes), | ||||
|         trailing: Text(_value), | ||||
|         subtitle: Text(_value), | ||||
|         trailing: Text(_date), | ||||
|         leading: _icon, | ||||
|         onTap: () { | ||||
|           if (InvenTreeStockItemTestResult().canCreate) { | ||||
|             addTestResult( | ||||
|                 context, | ||||
|                 name: _test, | ||||
|                 templateId: _templateId, | ||||
|                 nameIsEditable: !_required, | ||||
|                 valueRequired: _valueRequired, | ||||
|                 attachmentRequired: _attachmentRequired | ||||
|             ); | ||||
|           } | ||||
|         } | ||||
|       )); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user