mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 11:36:24 +00:00
* refactor attachment code into its own file * Add getters * Remove custom models for each type of attachment * Refactor existing widgets * Fix double camera open bug * Add check for modern parameter API * Add generic parameter type * Remove old code * Remove dead code * Refactor previous widget * Remove unused imports * Refactor common code * format * Update release notes * Helper func to render parameters list tile * Display parameters on part page * parameters for company * Supplier more model types: - ManufacturerPart - SupplierPart - PurchaseOrder - SalesOrder * dart format * Fix image prefix * Remove unused import * Adjust API version
77 lines
1.9 KiB
Dart
77 lines
1.9 KiB
Dart
import "package:inventree/inventree/model.dart";
|
|
|
|
class InvenTreeParameter extends InvenTreeModel {
|
|
InvenTreeParameter() : super();
|
|
|
|
InvenTreeParameter.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
|
|
|
@override
|
|
InvenTreeParameter createFromJson(Map<String, dynamic> json) =>
|
|
InvenTreeParameter.fromJson(json);
|
|
|
|
@override
|
|
String get URL => "parameter/";
|
|
|
|
@override
|
|
Map<String, Map<String, dynamic>> formFields() {
|
|
Map<String, Map<String, dynamic>> fields = {
|
|
"header": {
|
|
"type": "string",
|
|
"read_only": true,
|
|
"label": name,
|
|
"help_text": description,
|
|
"value": "",
|
|
},
|
|
"data": {"type": "string"},
|
|
"note": {},
|
|
};
|
|
|
|
return fields;
|
|
}
|
|
|
|
@override
|
|
String get name => getString("name", subKey: "template_detail");
|
|
|
|
@override
|
|
String get description => getString("description", subKey: "template_detail");
|
|
|
|
String get value => getString("data");
|
|
|
|
String get valueString {
|
|
String v = value;
|
|
|
|
if (units.isNotEmpty) {
|
|
v += " ";
|
|
v += units;
|
|
}
|
|
|
|
return v;
|
|
}
|
|
|
|
bool get as_bool => value.toLowerCase() == "true";
|
|
|
|
String get units => getString("units", subKey: "template_detail");
|
|
|
|
bool get is_checkbox =>
|
|
getBool("checkbox", subKey: "template_detail", backup: false);
|
|
|
|
// The model type of the instance this attachment is associated with
|
|
String get modelType => getString("model_type");
|
|
|
|
// The ID of the instance this attachment is associated with
|
|
int get modelId => getInt("model_id");
|
|
|
|
// Return a count of how many parameters exist against the specified model ID
|
|
Future<int> countParameters(String modelType, int modelId) async {
|
|
Map<String, String> filters = {};
|
|
|
|
if (!api.supportsModernParameters) {
|
|
return 0;
|
|
}
|
|
|
|
filters["model_type"] = modelType;
|
|
filters["model_id"] = modelId.toString();
|
|
|
|
return count(filters: filters);
|
|
}
|
|
}
|