mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-17 04:35:26 +00:00
Adds new custom widget for displaying Bill of Materials data
This commit is contained in:
69
lib/inventree/bom.dart
Normal file
69
lib/inventree/bom.dart
Normal file
@ -0,0 +1,69 @@
|
||||
|
||||
|
||||
import "package:inventree/inventree/model.dart";
|
||||
import "package:inventree/inventree/part.dart";
|
||||
|
||||
/*
|
||||
* Class representing the BomItem database model
|
||||
*/
|
||||
class InvenTreeBomItem extends InvenTreeModel {
|
||||
|
||||
InvenTreeBomItem() : super();
|
||||
|
||||
InvenTreeBomItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||
|
||||
@override
|
||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||
return InvenTreeBomItem.fromJson(json);
|
||||
}
|
||||
|
||||
@override
|
||||
String get URL => "bom/";
|
||||
|
||||
@override
|
||||
Map<String, String> defaultListFilters() {
|
||||
return {
|
||||
"sub_part_detail": "true",
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> defaultGetFilters() {
|
||||
return {
|
||||
"sub_part_detail": "true",
|
||||
};
|
||||
}
|
||||
|
||||
// Extract the 'quantity' value associated with this BomItem
|
||||
double get quantity => double.tryParse(jsondata["quantity"].toString()) ?? 0;
|
||||
|
||||
// Extract the ID of the related part
|
||||
int get partId => int.tryParse(jsondata["part"].toString()) ?? -1;
|
||||
|
||||
// Return a Part instance for the referenced part
|
||||
InvenTreePart? get part {
|
||||
if (jsondata.containsKey("part_detail")) {
|
||||
dynamic data = jsondata["part_detail"] ?? {};
|
||||
if (data is Map<String, dynamic>) {
|
||||
return InvenTreePart.fromJson(data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return a Part instance for the referenced sub-part
|
||||
InvenTreePart? get subPart {
|
||||
if (jsondata.containsKey("sub_part_detail")) {
|
||||
dynamic data = jsondata["sub_part_detail"] ?? {};
|
||||
if (data is Map<String, dynamic>) {
|
||||
return InvenTreePart.fromJson(data);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Extract the ID of the related sub-part
|
||||
int get subPartId => int.tryParse(jsondata["sub_part"].toString()) ?? -1;
|
||||
}
|
@ -10,6 +10,9 @@ import "package:inventree/l10.dart";
|
||||
import "package:inventree/inventree/model.dart";
|
||||
|
||||
|
||||
/*
|
||||
* Class representing the PartCategory database model
|
||||
*/
|
||||
class InvenTreePartCategory extends InvenTreeModel {
|
||||
|
||||
InvenTreePartCategory() : super();
|
||||
@ -70,6 +73,9 @@ class InvenTreePartCategory extends InvenTreeModel {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class representing the PartTestTemplate database model
|
||||
*/
|
||||
class InvenTreePartTestTemplate extends InvenTreeModel {
|
||||
|
||||
InvenTreePartTestTemplate() : super();
|
||||
@ -122,6 +128,9 @@ class InvenTreePartTestTemplate extends InvenTreeModel {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class representing the Part database model
|
||||
*/
|
||||
class InvenTreePart extends InvenTreeModel {
|
||||
|
||||
InvenTreePart() : super();
|
||||
@ -219,7 +228,6 @@ class InvenTreePart extends InvenTreeModel {
|
||||
return _supplierParts;
|
||||
}
|
||||
|
||||
|
||||
// Cached list of test templates
|
||||
List<InvenTreePartTestTemplate> testingTemplates = [];
|
||||
|
||||
|
Reference in New Issue
Block a user