mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 21:05:42 +00:00 
			
		
		
		
	Stock item serial number functionality (#199)
* Stock item serial number functionality - Allow serial numbers to be specified when creating a new stock item - Allow serial number to be edited from stock item context * Update build number and release notes
This commit is contained in:
		| @@ -1,6 +1,12 @@ | ||||
| ## InvenTree App Release Notes | ||||
| --- | ||||
|  | ||||
| ### 0.8.2 - August 2022 | ||||
| --- | ||||
|  | ||||
| - Allow serial numbers to be specified when creating new stock items | ||||
| - Allow serial numbers to be edited for existing stock items | ||||
|  | ||||
| ### 0.8.1 - August 2022 | ||||
| --- | ||||
|  | ||||
|   | ||||
| @@ -855,17 +855,18 @@ Future<void> launchApiForm( | ||||
|       IconData icon = FontAwesomeIcons.save, | ||||
|     }) async { | ||||
|  | ||||
|   showLoadingOverlay(context); | ||||
|  | ||||
|   // List of fields defined by the server | ||||
|   Map<String, dynamic> serverFields = {}; | ||||
|  | ||||
|   if (url.isNotEmpty) { | ||||
|  | ||||
|     showLoadingOverlay(context); | ||||
|     var options = await InvenTreeAPI().options(url); | ||||
|     hideLoadingOverlay(); | ||||
|  | ||||
|     // Invalid response from server | ||||
|     if (!options.isValid()) { | ||||
|       hideLoadingOverlay(); | ||||
|       return; | ||||
|     } | ||||
|  | ||||
| @@ -878,6 +879,7 @@ Future<void> launchApiForm( | ||||
|         icon: FontAwesomeIcons.userTimes, | ||||
|       ); | ||||
|  | ||||
|       hideLoadingOverlay(); | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| @@ -927,6 +929,8 @@ Future<void> launchApiForm( | ||||
|     await field.loadInitialData(); | ||||
|   } | ||||
|  | ||||
|   hideLoadingOverlay(); | ||||
|  | ||||
|   // Now, launch a new widget! | ||||
|   Navigator.push( | ||||
|     context, | ||||
| @@ -1067,7 +1071,6 @@ class _APIFormWidgetState extends State<APIFormWidget> { | ||||
|           spacerRequired = true; | ||||
|           break; | ||||
|       } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     return widgets; | ||||
|   | ||||
| @@ -199,6 +199,11 @@ class InvenTreeStockItem extends InvenTreeModel { | ||||
|       "part": {}, | ||||
|       "location": {}, | ||||
|       "quantity": {}, | ||||
|       "serial": {}, | ||||
|       "serial_numbers": { | ||||
|         "label": L10().serialNumber, | ||||
|         "type": "string", | ||||
|       }, | ||||
|       "status": {}, | ||||
|       "batch": {}, | ||||
|       "packaging": {}, | ||||
|   | ||||
| @@ -544,25 +544,53 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> { | ||||
|     return tiles; | ||||
|   } | ||||
|  | ||||
|   /* | ||||
|    * Launch a form to create a new StockItem for this part | ||||
|    */ | ||||
|   Future<void> _newStockItem(BuildContext context) async { | ||||
|  | ||||
|     var fields = InvenTreeStockItem().formFields(); | ||||
|  | ||||
|     // Serial number cannot be directly edited here | ||||
|     fields.remove("serial"); | ||||
|  | ||||
|     // Hide the "part" field | ||||
|     fields["part"]["hidden"] = true; | ||||
|  | ||||
|     int? default_location = part.defaultLocation; | ||||
|  | ||||
|     Map<String, dynamic> data = { | ||||
|       "part": part.pk.toString() | ||||
|     }; | ||||
|  | ||||
|     if (default_location != null) { | ||||
|       fields["location"]["value"] = default_location; | ||||
|       data["location"] = default_location; | ||||
|     } | ||||
|  | ||||
|     if (part.isTrackable) { | ||||
|       // read the next available serial number | ||||
|       showLoadingOverlay(context); | ||||
|       var response = await InvenTreeAPI().get("/api/part/${part.pk}/serial-numbers/", expectedStatusCode: null); | ||||
|       hideLoadingOverlay(); | ||||
|  | ||||
|       if (response.isValid() && response.statusCode == 200) { | ||||
|         data["serial_numbers"] = response.data["next"] ?? response.data["latest"]; | ||||
|       } | ||||
|  | ||||
|       print("response: " + response.statusCode.toString() + response.data.toString()); | ||||
|  | ||||
|     } else { | ||||
|       // Cannot set serial numbers for non-trackable parts | ||||
|       fields.remove("serial_numbers"); | ||||
|     } | ||||
|  | ||||
|     print("data: ${data.toString()}"); | ||||
|  | ||||
|     InvenTreeStockItem().createForm( | ||||
|         context, | ||||
|         L10().stockItemCreate, | ||||
|         fields: fields, | ||||
|         data: { | ||||
|           "part": "${part.pk}", | ||||
|         }, | ||||
|         data: data, | ||||
|         onSuccess: (result) async { | ||||
|  | ||||
|           Map<String, dynamic> data = result as Map<String, dynamic>; | ||||
|   | ||||
| @@ -292,6 +292,11 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | ||||
|     fields.remove("part"); | ||||
|     fields.remove("quantity"); | ||||
|     fields.remove("location"); | ||||
|     fields.remove("serial_numbers"); | ||||
|  | ||||
|     if (part == null || !part!.isTrackable) { | ||||
|       fields.remove("serial"); | ||||
|     } | ||||
|  | ||||
|     item.editForm( | ||||
|       context, | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| name: inventree | ||||
| description: InvenTree stock management | ||||
|  | ||||
| version: 0.8.1+47 | ||||
| version: 0.8.2+48 | ||||
|  | ||||
| environment: | ||||
|   sdk: ">=2.16.0 <3.0.0" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user