mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 05:15:42 +00:00 
			
		
		
		
	Add class for StockItemTestResult
This commit is contained in:
		| @@ -1,10 +1,34 @@ | ||||
| import 'dart:convert'; | ||||
|  | ||||
| import 'package:flutter/cupertino.dart'; | ||||
| import 'package:http/http.dart' as http; | ||||
| import 'model.dart'; | ||||
|  | ||||
| import 'package:InvenTree/api.dart'; | ||||
|  | ||||
|  | ||||
| class InvenTreeStockItemTestResult extends InvenTreeModel { | ||||
|  | ||||
|   @override | ||||
|   String NAME = "StockItemTestResult"; | ||||
|  | ||||
|   @override | ||||
|   String URL = "stock/test/"; | ||||
|  | ||||
|   InvenTreeStockItemTestResult() : super(); | ||||
|  | ||||
|   InvenTreeStockItemTestResult.fromJson(Map<String, dynamic> json) : super.fromJson(json) { | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   InvenTreeStockItemTestResult createFromJson(Map<String, dynamic> json) { | ||||
|     var result = InvenTreeStockItemTestResult.fromJson(json); | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| class InvenTreeStockItem extends InvenTreeModel { | ||||
|  | ||||
|   @override | ||||
| @@ -43,6 +67,29 @@ class InvenTreeStockItem extends InvenTreeModel { | ||||
|     // TODO | ||||
|   } | ||||
|  | ||||
|   List<InvenTreeStockItemTestResult> testResults = List<InvenTreeStockItemTestResult>(); | ||||
|  | ||||
|   int get testResultCount => testResults.length; | ||||
|  | ||||
|   Future<void> getTestResults(BuildContext context, {bool showDialog=false}) async { | ||||
|     InvenTreeStockItemTestResult().list( | ||||
|       context, | ||||
|       filters: { | ||||
|         "stock_item": "${pk}", | ||||
|         "user_detail": "true", | ||||
|       }, | ||||
|       dialog: showDialog, | ||||
|     ).then((var results) { | ||||
|       testResults.clear(); | ||||
|  | ||||
|       for (var r in results) { | ||||
|         if (r is InvenTreeStockItemTestResult) { | ||||
|           testResults.add(r); | ||||
|         } | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   int get partId => jsondata['part'] ?? -1; | ||||
|  | ||||
|   int get trackingItemCount => jsondata['tracking_items'] as int ?? 0; | ||||
|   | ||||
| @@ -20,7 +20,7 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> { | ||||
|  | ||||
|   // Function called after the widget is first build | ||||
|   Future<void> onBuild(BuildContext context) async { | ||||
|     return; | ||||
|     refresh(); | ||||
|   } | ||||
|  | ||||
|   // Function to request data for this page | ||||
|   | ||||
| @@ -53,6 +53,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | ||||
|   @override | ||||
|   Future<void> request(BuildContext context) async { | ||||
|     await item.reload(context); | ||||
|     await item.getTestResults(context); | ||||
|   } | ||||
|  | ||||
|   void _editStockItem() { | ||||
| @@ -423,6 +424,15 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     tiles.add( | ||||
|         ListTile( | ||||
|           title: Text("Test Results"), | ||||
|           leading: FaIcon(FontAwesomeIcons.tasks), | ||||
|           trailing: Text("${item.testResultCount}"), | ||||
|           onTap: null, | ||||
|         ) | ||||
|     ); | ||||
|  | ||||
|     if (item.trackingItemCount > 0) { | ||||
|       tiles.add( | ||||
|         ListTile( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user