mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-14 03:56:24 +00:00
Major refactoring for model data accessors
This commit is contained in:
parent
bfb582efb2
commit
bff2a5e2a9
7 changed files with 188 additions and 227 deletions
|
|
@ -59,23 +59,23 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
|||
};
|
||||
}
|
||||
|
||||
String get issueDate => (jsondata["issue_date"] ?? "") as String;
|
||||
String get issueDate => getString("issue_date");
|
||||
|
||||
String get completeDate => (jsondata["complete_date"] ?? "") as String;
|
||||
String get completeDate => getString("complete_date");
|
||||
|
||||
String get creationDate => (jsondata["creation_date"] ?? "") as String;
|
||||
String get creationDate => getString("creation_date");
|
||||
|
||||
String get targetDate => (jsondata["target_date"] ?? "") as String;
|
||||
String get targetDate => getString("target_date");
|
||||
|
||||
int get lineItemCount => (jsondata["line_items"] ?? 0) as int;
|
||||
int get lineItemCount => getInt("line_items", backup: 0);
|
||||
|
||||
bool get overdue => getBool("overdue");
|
||||
|
||||
bool get overdue => (jsondata["overdue"] ?? false) as bool;
|
||||
String get reference => getString("reference");
|
||||
|
||||
String get reference => (jsondata["reference"] ?? "") as String;
|
||||
int get responsibleId => getInt("responsible");
|
||||
|
||||
int get responsibleId => (jsondata["responsible"] ?? -1) as int;
|
||||
|
||||
int get supplierId => (jsondata["supplier"] ?? -1) as int;
|
||||
int get supplierId => getInt("supplier");
|
||||
|
||||
InvenTreeCompany? get supplier {
|
||||
|
||||
|
|
@ -88,11 +88,11 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
|||
}
|
||||
}
|
||||
|
||||
String get supplierReference => (jsondata["supplier_reference"] ?? "") as String;
|
||||
String get supplierReference => getString("supplier_reference");
|
||||
|
||||
int get status => (jsondata["status"] ?? -1) as int;
|
||||
int get status => getInt("status");
|
||||
|
||||
String get statusText => (jsondata["status_text"] ?? "") as String;
|
||||
String get statusText => getString("status_text");
|
||||
|
||||
bool get isOpen => status == PO_STATUS_PENDING || status == PO_STATUS_PLACED;
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
|||
bool get isFailed => status == PO_STATUS_CANCELLED || status == PO_STATUS_LOST || status == PO_STATUS_RETURNED;
|
||||
|
||||
double? get totalPrice {
|
||||
String price = (jsondata["total_price"] ?? "") as String;
|
||||
String price = getString("total_price");
|
||||
|
||||
if (price.isEmpty) {
|
||||
return null;
|
||||
|
|
@ -112,7 +112,7 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
|||
}
|
||||
}
|
||||
|
||||
String get totalPriceCurrency => (jsondata["total_price_currency"] ?? "") as String;
|
||||
String get totalPriceCurrency => getString("total_price_currency");
|
||||
|
||||
Future<List<InvenTreePOLineItem>> getLineItems() async {
|
||||
|
||||
|
|
@ -199,17 +199,17 @@ class InvenTreePOLineItem extends InvenTreeModel {
|
|||
|
||||
bool get isComplete => received >= quantity;
|
||||
|
||||
double get quantity => (jsondata["quantity"] ?? 0) as double;
|
||||
double get quantity => getDouble("quantity");
|
||||
|
||||
double get received => (jsondata["received"] ?? 0) as double;
|
||||
double get received => getDouble("received");
|
||||
|
||||
double get outstanding => quantity - received;
|
||||
|
||||
String get reference => (jsondata["reference"] ?? "") as String;
|
||||
String get reference => getString("reference");
|
||||
|
||||
int get orderId => (jsondata["order"] ?? -1) as int;
|
||||
int get orderId => getInt("order");
|
||||
|
||||
int get supplierPartId => (jsondata["part"] ?? -1) as int;
|
||||
int get supplierPartId => getInt("part");
|
||||
|
||||
InvenTreePart? get part {
|
||||
dynamic part_detail = jsondata["part_detail"];
|
||||
|
|
@ -232,16 +232,16 @@ class InvenTreePOLineItem extends InvenTreeModel {
|
|||
}
|
||||
}
|
||||
|
||||
double get purchasePrice => double.parse((jsondata["purchase_price"] ?? "") as String);
|
||||
double get purchasePrice => getDouble("purchase_price");
|
||||
|
||||
String get purchasePriceCurrency => getString("purchase_price_currency");
|
||||
|
||||
String get purchasePriceCurrency => (jsondata["purchase_price_currency"] ?? "") as String;
|
||||
String get purchasePriceString => getString("purchase_price_string");
|
||||
|
||||
String get purchasePriceString => (jsondata["purchase_price_string"] ?? "") as String;
|
||||
|
||||
int get destination => (jsondata["destination"] ?? -1) as int;
|
||||
|
||||
Map<String, dynamic> get destinationDetail => (jsondata["destination_detail"] ?? {}) as Map<String, dynamic>;
|
||||
int get destination => getInt("destination");
|
||||
|
||||
Map<String, dynamic> get destinationDetail => getMap("destination_detail");
|
||||
|
||||
@override
|
||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||
return InvenTreePOLineItem.fromJson(json);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue