mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 05:15:42 +00:00 
			
		
		
		
	Bug fix and refactoring
- Display difference between "in stock" and "unallocated stock" - Refactor to use single function in detail and list widgets
This commit is contained in:
		| @@ -269,17 +269,18 @@ class InvenTreePart extends InvenTreeModel { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Get the 'available stock' for this Part |     // Get the 'available stock' for this Part | ||||||
|     double get availableStock { |     double get unallocatedStock { | ||||||
|  |  | ||||||
|       // Note that the 'available_stock' was not added until API v35 |       // Note that the 'available_stock' was not added until API v35 | ||||||
|       if (jsondata.containsKey("available_stock")) { |       if (jsondata.containsKey("unallocated_stock")) { | ||||||
|         return double.tryParse(jsondata["available_stock"].toString()) ?? 0; |         return double.tryParse(jsondata["unallocated_stock"].toString()) ?? 0; | ||||||
|       } else { |       } else { | ||||||
|         return inStock; |         return inStock; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     String get availableStockString { |     String get unallocatedStockString { | ||||||
|       String q = simpleNumberString(availableStock); |       String q = simpleNumberString(unallocatedStock); | ||||||
|  |  | ||||||
|       if (units.isNotEmpty) { |       if (units.isNotEmpty) { | ||||||
|         q += " ${units}"; |         q += " ${units}"; | ||||||
| @@ -288,6 +289,20 @@ class InvenTreePart extends InvenTreeModel { | |||||||
|       return q; |       return q; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     String stockString({bool includeUnits = true}) { | ||||||
|  |       String q = unallocatedStockString; | ||||||
|  |  | ||||||
|  |       if (unallocatedStock != inStock) { | ||||||
|  |         q += " / ${inStockString}"; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (includeUnits && units.isNotEmpty) { | ||||||
|  |         q += " ${units}"; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       return q; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     String get units => (jsondata["units"] ?? "") as String; |     String get units => (jsondata["units"] ?? "") as String; | ||||||
|  |  | ||||||
|     // Get the number of units being build for this Part |     // Get the number of units being build for this Part | ||||||
|   | |||||||
| @@ -204,24 +204,24 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> { | |||||||
|       ); |       ); | ||||||
|     } else { |     } else { | ||||||
|       tiles.add( |       tiles.add( | ||||||
|         ListTile( |           ListTile( | ||||||
|           title: Text(L10().partCategory), |             title: Text(L10().partCategory), | ||||||
|           subtitle: Text(L10().partCategoryTopLevel), |             subtitle: Text(L10().partCategoryTopLevel), | ||||||
|           leading: FaIcon(FontAwesomeIcons.sitemap, color: COLOR_CLICK), |             leading: FaIcon(FontAwesomeIcons.sitemap, color: COLOR_CLICK), | ||||||
|           onTap: () { |             onTap: () { | ||||||
|             Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null))); |               Navigator.push(context, MaterialPageRoute( | ||||||
|           }, |                   builder: (context) => CategoryDisplayWidget(null))); | ||||||
|         ) |             }, | ||||||
|  |           ) | ||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Stock information |  | ||||||
|     tiles.add( |     tiles.add( | ||||||
|       ListTile( |       ListTile( | ||||||
|         title: Text(L10().availableStock), |         title: Text(L10().availableStock), | ||||||
|         subtitle: Text(L10().stockDetails), |         subtitle: Text(L10().stockDetails), | ||||||
|         leading: FaIcon(FontAwesomeIcons.boxes, color: COLOR_CLICK), |         leading: FaIcon(FontAwesomeIcons.boxes, color: COLOR_CLICK), | ||||||
|         trailing: Text(part.availableStockString), |         trailing: Text(part.stockString()), | ||||||
|         onTap: () { |         onTap: () { | ||||||
|           setState(() { |           setState(() { | ||||||
|             tabIndex = 1; |             tabIndex = 1; | ||||||
|   | |||||||
| @@ -87,7 +87,7 @@ class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> { | |||||||
|     return ListTile( |     return ListTile( | ||||||
|       title: Text(part.fullname), |       title: Text(part.fullname), | ||||||
|       subtitle: Text(part.description), |       subtitle: Text(part.description), | ||||||
|       trailing: Text(part.availableStockString), |       trailing: Text(part.stockString()), | ||||||
|       leading: InvenTreeAPI().getImage( |       leading: InvenTreeAPI().getImage( | ||||||
|         part.thumbnail, |         part.thumbnail, | ||||||
|         width: 40, |         width: 40, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user