2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 21:46:46 +00:00
Oliver e23a8b4d5e
Project code support (#336)
* Determine if project codes are supported

* Add helpers for boolean functions

* Adds helper methods for generic "model" class

- Will allow us to do some good refactoring

* Refactor the refactor

* Add debug support and getMap function

* Major refactoring for model data accessors

* Handle null values

* Add sentry reporting if key is used incorrectly

* Fix typo

* Refactor createFromJson function

* Add model for ProjectCode

* Display and edit project code for purchase orders
2023-04-21 21:12:22 +10:00

71 lines
1.7 KiB
Dart

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) => InvenTreeBomItem.fromJson(json);
@override
String get URL => "bom/";
@override
Map<String, String> defaultListFilters() {
return {
"sub_part_detail": "true",
"part_detail": "true",
"show_pricing": "false",
};
}
@override
Map<String, String> defaultGetFilters() {
return {
"sub_part_detail": "true",
};
}
// Extract the 'reference' value associated with this BomItem
String get reference => getString("reference");
// Extract the 'quantity' value associated with this BomItem
double get quantity => getDouble("quantity");
// Extract the ID of the related part
int get partId => getInt("part");
// 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 => getInt("sub_part");
}