mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-15 19:55:27 +00:00
Refactor createFromJson function
This commit is contained in:
@ -12,9 +12,7 @@ class InvenTreeBomItem extends InvenTreeModel {
|
|||||||
InvenTreeBomItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeBomItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeBomItem.fromJson(json);
|
||||||
return InvenTreeBomItem.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "bom/";
|
String get URL => "bom/";
|
||||||
|
@ -81,11 +81,7 @@ class InvenTreeCompany extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeCompany.fromJson(json);
|
||||||
var company = InvenTreeCompany.fromJson(json);
|
|
||||||
|
|
||||||
return company;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -183,11 +179,7 @@ class InvenTreeSupplierPart extends InvenTreeModel {
|
|||||||
String get note => getString("note");
|
String get note => getString("note");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeSupplierPart.fromJson(json);
|
||||||
var part = InvenTreeSupplierPart.fromJson(json);
|
|
||||||
|
|
||||||
return part;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -214,9 +206,5 @@ class InvenTreeManufacturerPart extends InvenTreeModel {
|
|||||||
String get MPN => getString("MPN");
|
String get MPN => getString("MPN");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeManufacturerPart.fromJson(json);
|
||||||
var part = InvenTreeManufacturerPart.fromJson(json);
|
|
||||||
|
|
||||||
return part;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -390,12 +390,7 @@ class InvenTreeModel {
|
|||||||
String get keywords => getString("keywords");
|
String get keywords => getString("keywords");
|
||||||
|
|
||||||
// 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) => InvenTreeModel.fromJson(json);
|
||||||
|
|
||||||
var obj = InvenTreeModel.fromJson(json);
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the API detail endpoint for this Model object
|
// Return the API detail endpoint for this Model object
|
||||||
String get url => "${URL}/${pk}/".replaceAll("//", "/");
|
String get url => "${URL}/${pk}/".replaceAll("//", "/");
|
||||||
@ -836,9 +831,7 @@ class InvenTreePlugin extends InvenTreeModel {
|
|||||||
InvenTreePlugin.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePlugin.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePlugin.fromJson(json);
|
||||||
return InvenTreePlugin.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL {
|
String get URL {
|
||||||
|
@ -67,11 +67,7 @@ class InvenTreePartCategory extends InvenTreeModel {
|
|||||||
int get partcount => (jsondata["part_count"] ?? jsondata["parts"] ?? 0) as int;
|
int get partcount => (jsondata["part_count"] ?? jsondata["parts"] ?? 0) as int;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartCategory.fromJson(json);
|
||||||
var cat = InvenTreePartCategory.fromJson(json);
|
|
||||||
|
|
||||||
return cat;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,11 +94,7 @@ class InvenTreePartTestTemplate extends InvenTreeModel {
|
|||||||
bool get requiresAttachment => getBool("requires_attachment");
|
bool get requiresAttachment => getBool("requires_attachment");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartTestTemplate.fromJson(json);
|
||||||
var template = InvenTreePartTestTemplate.fromJson(json);
|
|
||||||
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool passFailStatus() {
|
bool passFailStatus() {
|
||||||
|
|
||||||
@ -142,9 +134,7 @@ class InvenTreePartParameter extends InvenTreeModel {
|
|||||||
String get URL => "part/parameter/";
|
String get URL => "part/parameter/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartParameter.fromJson(json);
|
||||||
return InvenTreePartParameter.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> formFields() {
|
Map<String, dynamic> formFields() {
|
||||||
@ -445,12 +435,7 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
bool get starred => getBool("starred");
|
bool get starred => getBool("starred");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePart.fromJson(json);
|
||||||
|
|
||||||
var part = InvenTreePart.fromJson(json);
|
|
||||||
|
|
||||||
return part;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -469,8 +454,6 @@ class InvenTreePartAttachment extends InvenTreeAttachment {
|
|||||||
String get URL => "part/attachment/";
|
String get URL => "part/attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartAttachment.fromJson(json);
|
||||||
return InvenTreePartAttachment.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,9 +134,7 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePurchaseOrder.fromJson(json);
|
||||||
return InvenTreePurchaseOrder.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mark this order as "placed" / "issued"
|
/// Mark this order as "placed" / "issued"
|
||||||
Future<void> issueOrder() async {
|
Future<void> issueOrder() async {
|
||||||
@ -243,9 +241,8 @@ class InvenTreePOLineItem extends InvenTreeModel {
|
|||||||
Map<String, dynamic> get destinationDetail => getMap("destination_detail");
|
Map<String, dynamic> get destinationDetail => getMap("destination_detail");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePOLineItem.fromJson(json);
|
||||||
return InvenTreePOLineItem.fromJson(json);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -264,7 +261,6 @@ class InvenTreePurchaseOrderAttachment extends InvenTreeAttachment {
|
|||||||
String get URL => "order/po/attachment/";
|
String get URL => "order/po/attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePurchaseOrderAttachment.fromJson(json);
|
||||||
return InvenTreePurchaseOrderAttachment.fromJson(json);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -63,9 +63,7 @@ class InvenTreeStockItemHistory extends InvenTreeModel {
|
|||||||
InvenTreeStockItemHistory.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeStockItemHistory.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockItemHistory.fromJson(json);
|
||||||
return InvenTreeStockItemHistory.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "stock/track/";
|
String get URL => "stock/track/";
|
||||||
@ -472,9 +470,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockItem.fromJson(json);
|
||||||
return InvenTreeStockItem.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform stocktake action:
|
* Perform stocktake action:
|
||||||
@ -576,9 +572,7 @@ class InvenTreeStockItemAttachment extends InvenTreeAttachment {
|
|||||||
String get URL => "stock/attachment/";
|
String get URL => "stock/attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockItemAttachment.fromJson(json);
|
||||||
return InvenTreeStockItemAttachment.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,10 +627,6 @@ class InvenTreeStockLocation extends InvenTreeModel {
|
|||||||
int get itemcount => (jsondata["items"] ?? 0) as int;
|
int get itemcount => (jsondata["items"] ?? 0) as int;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockLocation.fromJson(json);
|
||||||
|
|
||||||
var loc = InvenTreeStockLocation.fromJson(json);
|
}
|
||||||
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user