2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-07-11 08:04:14 +00:00

More linting work

This commit is contained in:
Oliver
2021-09-28 20:24:55 +10:00
parent c1152ee286
commit ad0cc36540
50 changed files with 915 additions and 918 deletions

View File

@ -1,15 +1,13 @@
import 'package:intl/intl.dart';
import 'package:inventree/inventree/part.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'model.dart';
import 'package:inventree/l10.dart';
import "dart:async";
import "package:intl/intl.dart";
import "package:inventree/inventree/part.dart";
import "package:flutter/cupertino.dart";
import 'dart:async';
import 'dart:io';
import "package:inventree/inventree/model.dart";
import "package:inventree/l10.dart";
import 'package:inventree/api.dart';
import "package:inventree/api.dart";
class InvenTreeStockItemTestResult extends InvenTreeModel {
@ -31,19 +29,17 @@ class InvenTreeStockItemTestResult extends InvenTreeModel {
};
}
String get key => (jsondata['key'] ?? '') as String;
String get key => (jsondata["key"] ?? "") as String;
String get testName => (jsondata['test'] ?? '') as String;
String get testName => (jsondata["test"] ?? "") as String;
bool get result => (jsondata['result'] ?? false) as bool;
bool get result => (jsondata["result"] ?? false) as bool;
String get value => (jsondata['value'] ?? '') as String;
String get value => (jsondata["value"] ?? "") as String;
String get notes => (jsondata['notes'] ?? '') as String;
String get attachment => (jsondata["attachment"] ?? "") as String;
String get attachment => (jsondata['attachment'] ?? '') as String;
String get date => (jsondata['date'] ?? '') as String;
String get date => (jsondata["date"] ?? "") as String;
InvenTreeStockItemTestResult() : super();
@ -204,17 +200,17 @@ class InvenTreeStockItem extends InvenTreeModel {
});
}
String get uid => (jsondata['uid'] ?? '') as String;
String get uid => (jsondata["uid"] ?? "") as String;
int get status => (jsondata['status'] ?? -1) as int;
int get status => (jsondata["status"] ?? -1) as int;
String get packaging => (jsondata["packaging"] ?? '') as String;
String get packaging => (jsondata["packaging"] ?? "") as String;
String get batch => (jsondata["batch"] ?? '') as String;
String get batch => (jsondata["batch"] ?? "") as String;
int get partId => (jsondata['part'] ?? -1) as int;
int get partId => (jsondata["part"] ?? -1) as int;
String get purchasePrice => (jsondata['purchase_price'] ?? '') as String;
String get purchasePrice => (jsondata["purchase_price"] ?? "") as String;
bool get hasPurchasePrice {
@ -223,14 +219,14 @@ class InvenTreeStockItem extends InvenTreeModel {
return pp.isNotEmpty && pp.trim() != "-";
}
int get purchaseOrderId => (jsondata['purchase_order'] ?? -1) as int;
int get purchaseOrderId => (jsondata["purchase_order"] ?? -1) as int;
int get trackingItemCount => (jsondata['tracking_items'] ?? 0) as int;
int get trackingItemCount => (jsondata["tracking_items"] ?? 0) as int;
// Date of last update
DateTime? get updatedDate {
if (jsondata.containsKey("updated")) {
return DateTime.tryParse((jsondata["updated"] ?? '') as String);
return DateTime.tryParse((jsondata["updated"] ?? "") as String);
} else {
return null;
}
@ -250,7 +246,7 @@ class InvenTreeStockItem extends InvenTreeModel {
DateTime? get stocktakeDate {
if (jsondata.containsKey("stocktake_date")) {
return DateTime.tryParse((jsondata["stocktake_date"] ?? '') as String);
return DateTime.tryParse((jsondata["stocktake_date"] ?? "") as String);
} else {
return null;
}
@ -270,45 +266,45 @@ class InvenTreeStockItem extends InvenTreeModel {
String get partName {
String nm = '';
String nm = "";
// Use the detailed part information as priority
if (jsondata.containsKey('part_detail')) {
nm = (jsondata['part_detail']['full_name'] ?? '') as String;
if (jsondata.containsKey("part_detail")) {
nm = (jsondata["part_detail"]["full_name"] ?? "") as String;
}
// Backup if first value fails
if (nm.isEmpty) {
nm = (jsondata['part__name'] ?? '') as String;
nm = (jsondata["part__name"] ?? "") as String;
}
return nm;
}
String get partDescription {
String desc = '';
String desc = "";
// Use the detailed part description as priority
if (jsondata.containsKey('part_detail')) {
desc = (jsondata['part_detail']['description'] ?? '') as String;
if (jsondata.containsKey("part_detail")) {
desc = (jsondata["part_detail"]["description"] ?? "") as String;
}
if (desc.isEmpty) {
desc = (jsondata['part__description'] ?? '') as String;
desc = (jsondata["part__description"] ?? "") as String;
}
return desc;
}
String get partImage {
String img = '';
String img = "";
if (jsondata.containsKey('part_detail')) {
img = (jsondata['part_detail']['thumbnail'] ?? '') as String;
if (jsondata.containsKey("part_detail")) {
img = (jsondata["part_detail"]["thumbnail"] ?? "") as String;
}
if (img.isEmpty) {
img = (jsondata['part__thumbnail'] ?? '') as String;
img = (jsondata["part__thumbnail"] ?? "") as String;
}
return img;
@ -321,63 +317,63 @@ class InvenTreeStockItem extends InvenTreeModel {
String thumb = "";
thumb = (jsondata['part_detail']?['thumbnail'] ?? '') as String;
thumb = (jsondata["part_detail"]?["thumbnail"] ?? "") as String;
// Use 'image' as a backup
// Use "image" as a backup
if (thumb.isEmpty) {
thumb = (jsondata['part_detail']?['image'] ?? '') as String;
thumb = (jsondata["part_detail"]?["image"] ?? "") as String;
}
// Try a different approach
if (thumb.isEmpty) {
thumb = (jsondata['part__thumbnail'] ?? '') as String;
thumb = (jsondata["part__thumbnail"] ?? "") as String;
}
// Still no thumbnail? Use the 'no image' image
// Still no thumbnail? Use the "no image" image
if (thumb.isEmpty) thumb = InvenTreeAPI.staticThumb;
return thumb;
}
int get supplierPartId => (jsondata['supplier_part'] ?? -1) as int;
int get supplierPartId => (jsondata["supplier_part"] ?? -1) as int;
String get supplierImage {
String thumb = '';
String thumb = "";
if (jsondata.containsKey("supplier_detail")) {
thumb = (jsondata['supplier_detail']['supplier_logo'] ?? '') as String;
thumb = (jsondata["supplier_detail"]["supplier_logo"] ?? "") as String;
}
return thumb;
}
String get supplierName {
String sname = '';
String sname = "";
if (jsondata.containsKey("supplier_detail")) {
sname = (jsondata["supplier_detail"]["supplier_name"] ?? '') as String;
sname = (jsondata["supplier_detail"]["supplier_name"] ?? "") as String;
}
return sname;
}
String get units {
return (jsondata['part_detail']?['units'] ?? '') as String;
return (jsondata["part_detail"]?["units"] ?? "") as String;
}
String get supplierSKU {
String sku = '';
String sku = "";
if (jsondata.containsKey("supplier_detail")) {
sku = (jsondata["supplier_detail"]["SKU"] ?? '') as String;
sku = (jsondata["supplier_detail"]["SKU"] ?? "") as String;
}
return sku;
}
String get serialNumber => (jsondata['serial'] ?? '') as String;
String get serialNumber => (jsondata["serial"] ?? "") as String;
double get quantity => double.tryParse(jsondata['quantity'].toString()) ?? 0;
double get quantity => double.tryParse(jsondata["quantity"].toString()) ?? 0;
String get quantityString {
@ -395,33 +391,33 @@ class InvenTreeStockItem extends InvenTreeModel {
return q;
}
int get locationId => (jsondata['location'] ?? -1) as int;
int get locationId => (jsondata["location"] ?? -1) as int;
bool isSerialized() => serialNumber.isNotEmpty && quantity.toInt() == 1;
String serialOrQuantityDisplay() {
if (isSerialized()) {
return 'SN ${serialNumber}';
return "SN ${serialNumber}";
}
// Is an integer?
if (quantity.toInt() == quantity) {
return '${quantity.toInt()}';
return "${quantity.toInt()}";
}
return '${quantity}';
return "${quantity}";
}
String get locationName {
String loc = '';
String loc = "";
if (locationId == -1 || !jsondata.containsKey('location_detail')) return 'Unknown Location';
if (locationId == -1 || !jsondata.containsKey("location_detail")) return "Unknown Location";
loc = (jsondata['location_detail']['name'] ?? '') as String;
loc = (jsondata["location_detail"]["name"] ?? "") as String;
// Old-style name
if (loc.isEmpty) {
loc = (jsondata['location__name'] ?? '') as String;
loc = (jsondata["location__name"] ?? "") as String;
}
return loc;
@ -429,9 +425,9 @@ class InvenTreeStockItem extends InvenTreeModel {
String get locationPathString {
if (locationId == -1 || !jsondata.containsKey('location_detail')) return L10().locationNotSet;
if (locationId == -1 || !jsondata.containsKey("location_detail")) return L10().locationNotSet;
String _loc = (jsondata['location_detail']['pathstring'] ?? '') as String;
String _loc = (jsondata["location_detail"]["pathstring"] ?? "") as String;
if (_loc.isNotEmpty) {
return _loc;
@ -483,7 +479,7 @@ class InvenTreeStockItem extends InvenTreeModel {
"pk": "${pk}",
"quantity": "${q}",
},
"notes": notes ?? '',
"notes": notes ?? "",
},
expectedStatusCode: 200
);
@ -540,7 +536,7 @@ class InvenTreeStockLocation extends InvenTreeModel {
@override
String get URL => "stock/location/";
String get pathstring => (jsondata['pathstring'] ?? '') as String;
String get pathstring => (jsondata["pathstring"] ?? "") as String;
@override
Map<String, dynamic> formFields() {
@ -553,13 +549,13 @@ class InvenTreeStockLocation extends InvenTreeModel {
String get parentpathstring {
// TODO - Drive the refactor tractor through this
List<String> psplit = pathstring.split('/');
List<String> psplit = pathstring.split("/");
if (psplit.length > 0) {
psplit.removeLast();
}
String p = psplit.join('/');
String p = psplit.join("/");
if (p.isEmpty) {
p = "Top level stock location";
@ -568,7 +564,7 @@ class InvenTreeStockLocation extends InvenTreeModel {
return p;
}
int get itemcount => (jsondata['items'] ?? 0) as int;
int get itemcount => (jsondata["items"] ?? 0) as int;
InvenTreeStockLocation() : super();