mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-11-04 15:25:48 +00:00 
			
		
		
		
	Merge pull request #100 from inventree/variant-of
Render link to "parent template part" (if it exists)
This commit is contained in:
		@@ -305,6 +305,9 @@ class InvenTreePart extends InvenTreeModel {
 | 
			
		||||
 | 
			
		||||
    String get units => (jsondata["units"] ?? "") as String;
 | 
			
		||||
 | 
			
		||||
    // Get the ID of the Part that this part is a variant of (or null)
 | 
			
		||||
    int? get variantOf => jsondata["variant_of"] as int?;
 | 
			
		||||
 | 
			
		||||
    // Get the number of units being build for this Part
 | 
			
		||||
    double get building => double.tryParse(jsondata["building"].toString()) ?? 0;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								lib/l10n
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								lib/l10n
									
									
									
									
									
								
							 Submodule lib/l10n updated: f4cb183197...cab0624b64
									
								
							@@ -37,6 +37,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
 | 
			
		||||
 | 
			
		||||
  InvenTreePart part;
 | 
			
		||||
 | 
			
		||||
  InvenTreePart? parentPart;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  String getAppBarTitle(BuildContext context) => L10().partDetails;
 | 
			
		||||
 | 
			
		||||
@@ -92,6 +94,21 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
 | 
			
		||||
      Navigator.of(context).pop();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // If the part points to a parent "template" part, request that too
 | 
			
		||||
    int? templatePartId = part.variantOf;
 | 
			
		||||
 | 
			
		||||
    if (templatePartId == null) {
 | 
			
		||||
      parentPart = null;
 | 
			
		||||
    } else {
 | 
			
		||||
      final result = await InvenTreePart().get(templatePartId);
 | 
			
		||||
 | 
			
		||||
      if (result != null && result is InvenTreePart) {
 | 
			
		||||
        parentPart = result;
 | 
			
		||||
      } else {
 | 
			
		||||
        parentPart = null;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    await part.getTestTemplates();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -182,6 +199,26 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (parentPart != null) {
 | 
			
		||||
      tiles.add(
 | 
			
		||||
        ListTile(
 | 
			
		||||
          title: Text(L10().templatePart),
 | 
			
		||||
          subtitle: Text(parentPart!.fullname),
 | 
			
		||||
          leading: InvenTreeAPI().getImage(
 | 
			
		||||
            parentPart!.thumbnail,
 | 
			
		||||
            width: 32,
 | 
			
		||||
            height: 32,
 | 
			
		||||
          ),
 | 
			
		||||
          onTap: () {
 | 
			
		||||
            Navigator.push(
 | 
			
		||||
              context,
 | 
			
		||||
              MaterialPageRoute(builder: (context) => PartDetailWidget(parentPart!))
 | 
			
		||||
            );
 | 
			
		||||
          }
 | 
			
		||||
        )
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Category information
 | 
			
		||||
    if (part.categoryName.isNotEmpty) {
 | 
			
		||||
      tiles.add(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user