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 | ## 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 | ### 0.8.1 - August 2022 | ||||||
| --- | --- | ||||||
|  |  | ||||||
|   | |||||||
| @@ -855,17 +855,18 @@ Future<void> launchApiForm( | |||||||
|       IconData icon = FontAwesomeIcons.save, |       IconData icon = FontAwesomeIcons.save, | ||||||
|     }) async { |     }) async { | ||||||
|  |  | ||||||
|  |   showLoadingOverlay(context); | ||||||
|  |  | ||||||
|   // List of fields defined by the server |   // List of fields defined by the server | ||||||
|   Map<String, dynamic> serverFields = {}; |   Map<String, dynamic> serverFields = {}; | ||||||
|  |  | ||||||
|   if (url.isNotEmpty) { |   if (url.isNotEmpty) { | ||||||
|  |  | ||||||
|     showLoadingOverlay(context); |  | ||||||
|     var options = await InvenTreeAPI().options(url); |     var options = await InvenTreeAPI().options(url); | ||||||
|     hideLoadingOverlay(); |  | ||||||
|  |  | ||||||
|     // Invalid response from server |     // Invalid response from server | ||||||
|     if (!options.isValid()) { |     if (!options.isValid()) { | ||||||
|  |       hideLoadingOverlay(); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -878,6 +879,7 @@ Future<void> launchApiForm( | |||||||
|         icon: FontAwesomeIcons.userTimes, |         icon: FontAwesomeIcons.userTimes, | ||||||
|       ); |       ); | ||||||
|  |  | ||||||
|  |       hideLoadingOverlay(); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @@ -927,6 +929,8 @@ Future<void> launchApiForm( | |||||||
|     await field.loadInitialData(); |     await field.loadInitialData(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   hideLoadingOverlay(); | ||||||
|  |  | ||||||
|   // Now, launch a new widget! |   // Now, launch a new widget! | ||||||
|   Navigator.push( |   Navigator.push( | ||||||
|     context, |     context, | ||||||
| @@ -1067,7 +1071,6 @@ class _APIFormWidgetState extends State<APIFormWidget> { | |||||||
|           spacerRequired = true; |           spacerRequired = true; | ||||||
|           break; |           break; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return widgets; |     return widgets; | ||||||
|   | |||||||
| @@ -199,6 +199,11 @@ class InvenTreeStockItem extends InvenTreeModel { | |||||||
|       "part": {}, |       "part": {}, | ||||||
|       "location": {}, |       "location": {}, | ||||||
|       "quantity": {}, |       "quantity": {}, | ||||||
|  |       "serial": {}, | ||||||
|  |       "serial_numbers": { | ||||||
|  |         "label": L10().serialNumber, | ||||||
|  |         "type": "string", | ||||||
|  |       }, | ||||||
|       "status": {}, |       "status": {}, | ||||||
|       "batch": {}, |       "batch": {}, | ||||||
|       "packaging": {}, |       "packaging": {}, | ||||||
|   | |||||||
| @@ -544,25 +544,53 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> { | |||||||
|     return tiles; |     return tiles; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /* | ||||||
|  |    * Launch a form to create a new StockItem for this part | ||||||
|  |    */ | ||||||
|   Future<void> _newStockItem(BuildContext context) async { |   Future<void> _newStockItem(BuildContext context) async { | ||||||
|  |  | ||||||
|     var fields = InvenTreeStockItem().formFields(); |     var fields = InvenTreeStockItem().formFields(); | ||||||
|  |  | ||||||
|  |     // Serial number cannot be directly edited here | ||||||
|  |     fields.remove("serial"); | ||||||
|  |  | ||||||
|  |     // Hide the "part" field | ||||||
|     fields["part"]["hidden"] = true; |     fields["part"]["hidden"] = true; | ||||||
|  |  | ||||||
|     int? default_location = part.defaultLocation; |     int? default_location = part.defaultLocation; | ||||||
|  |  | ||||||
|  |     Map<String, dynamic> data = { | ||||||
|  |       "part": part.pk.toString() | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     if (default_location != null) { |     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( |     InvenTreeStockItem().createForm( | ||||||
|         context, |         context, | ||||||
|         L10().stockItemCreate, |         L10().stockItemCreate, | ||||||
|         fields: fields, |         fields: fields, | ||||||
|         data: { |         data: data, | ||||||
|           "part": "${part.pk}", |  | ||||||
|         }, |  | ||||||
|         onSuccess: (result) async { |         onSuccess: (result) async { | ||||||
|  |  | ||||||
|           Map<String, dynamic> data = result as Map<String, dynamic>; |           Map<String, dynamic> data = result as Map<String, dynamic>; | ||||||
|   | |||||||
| @@ -292,6 +292,11 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | |||||||
|     fields.remove("part"); |     fields.remove("part"); | ||||||
|     fields.remove("quantity"); |     fields.remove("quantity"); | ||||||
|     fields.remove("location"); |     fields.remove("location"); | ||||||
|  |     fields.remove("serial_numbers"); | ||||||
|  |  | ||||||
|  |     if (part == null || !part!.isTrackable) { | ||||||
|  |       fields.remove("serial"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     item.editForm( |     item.editForm( | ||||||
|       context, |       context, | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| name: inventree | name: inventree | ||||||
| description: InvenTree stock management | description: InvenTree stock management | ||||||
|  |  | ||||||
| version: 0.8.1+47 | version: 0.8.2+48 | ||||||
|  |  | ||||||
| environment: | environment: | ||||||
|   sdk: ">=2.16.0 <3.0.0" |   sdk: ">=2.16.0 <3.0.0" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user