You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/models/part.dart

41 lines
1.0 KiB
Dart

class Part {
3 years ago
int id;
3 years ago
int reportPartID;
String partNo;
String partName;
3 years ago
int quantity;
double returnQty, installQty;
3 years ago
Part({
this.id,
3 years ago
this.reportPartID,
this.partNo,
this.partName,
3 years ago
this.quantity = 1,
this.installQty,
this.returnQty,
3 years ago
});
Map<String, dynamic> toJson() {
3 years ago
return {
"id": reportPartID ?? 0,
"sparePart": {"id": id, "partNo": partNo, "partName": partName},
"qty": quantity,
if (returnQty != null) "returnQty": returnQty,
if (installQty != null) "installQty": installQty,
3 years ago
};
}
factory Part.fromJson(Map<String, dynamic> parsedJson, {Map<String, dynamic> reportJson}) {
3 years ago
return Part(
id: parsedJson["id"],
3 years ago
reportPartID: reportJson != null ? reportJson["id"] : null,
partNo: parsedJson["partNo"],
partName: parsedJson["partName"],
3 years ago
quantity: reportJson != null ? (reportJson["qty"] ?? 1).toInt() : 1,
returnQty: parsedJson["returnQty"],
installQty: parsedJson["installQty"],
3 years ago
);
}
}