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