mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-29 05:56:47 +00:00
Some more value getters for Part model
This commit is contained in:
parent
06446998b2
commit
f84ba65f6c
@ -43,6 +43,8 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
int get parentId => jsondata['parent'] ?? -1;
|
int get parentId => jsondata['parent'] ?? -1;
|
||||||
|
|
||||||
|
String get link => jsondata['URL'] ?? '';
|
||||||
|
|
||||||
// Create a new object from JSON data (not a constructor!)
|
// Create a new object from JSON data (not a constructor!)
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:InvenTree/api.dart';
|
import 'package:InvenTree/api.dart';
|
||||||
|
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
@ -34,14 +36,63 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
@override
|
@override
|
||||||
String URL = "part/";
|
String URL = "part/";
|
||||||
|
|
||||||
int get categoryId => jsondata['category'] as int ?? -1;
|
// Get the number of stock on order for this Part
|
||||||
|
double get onOrder => double.tryParse(jsondata['on_order'].toString() ?? '0');
|
||||||
|
|
||||||
String get categoryName => jsondata['category__name'] ?? '';
|
// Get the stock count for this Part
|
||||||
|
double get inStock => double.tryParse(jsondata['total_stock'].toString() ?? '0');
|
||||||
|
|
||||||
|
// Get the number of units being build for this Part
|
||||||
|
double get building => double.tryParse(jsondata['building'].toString() ?? '0');
|
||||||
|
|
||||||
|
bool get isAssembly => jsondata['assembly'] ?? false;
|
||||||
|
|
||||||
|
bool get isComponent => jsondata['component'] ?? false;
|
||||||
|
|
||||||
|
bool get isPurchaseable => jsondata['purchaseable'] ?? false;
|
||||||
|
|
||||||
|
bool get isSaleable => jsondata['saleable'] ?? false;
|
||||||
|
|
||||||
|
bool get isActive => jsondata['active'] ?? false;
|
||||||
|
|
||||||
|
bool get isVirtual => jsondata['virtual'] ?? false;
|
||||||
|
|
||||||
|
// Get the IPN (internal part number) for the Part instance
|
||||||
|
String get IPN => jsondata['IPN'] as String ?? '';
|
||||||
|
|
||||||
|
// Get the revision string for the Part instance
|
||||||
|
String get revision => jsondata['revision'] as String ?? '';
|
||||||
|
|
||||||
|
// Get the category ID for the Part instance (or 'null' if does not exist)
|
||||||
|
int get categoryId => jsondata['category'] as int ?? null;
|
||||||
|
|
||||||
|
// Get the category name for the Part instance
|
||||||
|
String get categoryName => jsondata['category_name'] ?? '';
|
||||||
|
|
||||||
|
// Get the image URL for the Part instance
|
||||||
String get _image => jsondata['image'] ?? '';
|
String get _image => jsondata['image'] ?? '';
|
||||||
|
|
||||||
|
// Get the thumbnail URL for the Part instance
|
||||||
String get _thumbnail => jsondata['thumbnail'] ?? '';
|
String get _thumbnail => jsondata['thumbnail'] ?? '';
|
||||||
|
|
||||||
|
// Return the fully-qualified name for the Part instance
|
||||||
|
String get fullname {
|
||||||
|
|
||||||
|
String fn = jsondata['full_name'] ?? '';
|
||||||
|
|
||||||
|
if (fn.isNotEmpty) return fn;
|
||||||
|
|
||||||
|
List<String> elements = List<String>();
|
||||||
|
|
||||||
|
if (IPN.isNotEmpty) elements.add(IPN);
|
||||||
|
|
||||||
|
elements.add(name);
|
||||||
|
|
||||||
|
if (revision.isNotEmpty) elements.add(revision);
|
||||||
|
|
||||||
|
return elements.join(" | ");
|
||||||
|
}
|
||||||
|
|
||||||
// Return a path to the image for this Part
|
// Return a path to the image for this Part
|
||||||
String get image {
|
String get image {
|
||||||
// Use thumbnail as a backup
|
// Use thumbnail as a backup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user