From f6302bd65df07a50a5a3822d1ea0e5fcb66a2c93 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 26 Aug 2021 22:03:36 +1000 Subject: [PATCH] Add "units" for part - Edit "units" for a part - Display "units" after stock quantity --- assets/release_notes.md | 5 +++++ lib/inventree/part.dart | 16 +++++++++++++--- lib/inventree/stock.dart | 17 ++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/assets/release_notes.md b/assets/release_notes.md index 983069a5..48e606bf 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -1,6 +1,11 @@ ## InvenTree App Release Notes --- +### 0.4.7 - September 2021 +--- + +- Display units after stock quantity + ### 0.4.6 - August 2021 --- diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 63f11beb..13f7911a 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -142,6 +142,8 @@ class InvenTreePart extends InvenTreeModel { "category": { }, + "units": {}, + // Checkbox fields "active": {}, "assembly": {}, @@ -256,13 +258,21 @@ class InvenTreePart extends InvenTreeModel { String get inStockString { + String q = inStock.toString(); + if (inStock == inStock.toInt()) { - return inStock.toInt().toString(); - } else { - return inStock.toString(); + q = inStock.toInt().toString(); } + + if (units.isNotEmpty) { + q += " ${units}"; + } + + return q; } + String get units => jsondata["units"] ?? ""; + // Get the number of units being build for this Part double get building => double.tryParse(jsondata['building'].toString()) ?? 0; diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 9acc7059..795dbda7 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -359,6 +359,10 @@ class InvenTreeStockItem extends InvenTreeModel { return sname; } + String get units { + return jsondata['part_detail']?['units'] ?? ''; + } + String get supplierSKU { String sku = ''; @@ -375,11 +379,18 @@ class InvenTreeStockItem extends InvenTreeModel { String get quantityString { + String q = quantity.toString(); + + // Simplify integer values e.g. "1.0" becomes "1" if (quantity.toInt() == quantity) { - return quantity.toInt().toString(); - } else { - return quantity.toString(); + q = quantity.toInt().toString(); } + + if (units.isNotEmpty) { + q += " ${units}"; + } + + return q; } int get locationId => (jsondata['location'] ?? -1) as int;