From cbb668687e928d1ac8212492f7f01fa3e1465a41 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 29 Sep 2021 00:24:21 +1000 Subject: [PATCH] Set default location for part - Used as "default" when creating new StockItem for that part --- lib/api_form.dart | 2 +- lib/inventree/part.dart | 8 +++++--- lib/widget/part_detail.dart | 6 ++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/api_form.dart b/lib/api_form.dart index 95dad26f..32870769 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -395,7 +395,7 @@ class APIFormField { // Render a "related field" based on the "model" type // Convert to JSON - Map data = item as Map; + var data = Map.from((item ?? {}) as Map); switch (model) { case "part": diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 16b2562d..e327cb9c 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -139,9 +139,9 @@ class InvenTreePart extends InvenTreeModel { "keywords": {}, "link": {}, - // Parent category - "category": { - }, + "category": {}, + + "default_location": {}, "units": {}, @@ -242,6 +242,8 @@ class InvenTreePart extends InvenTreeModel { }); } + int? get defaultLocation => jsondata["default_location"] as int?; + // Get the number of stock on order for this Part double get onOrder => double.tryParse(jsondata["ordering"].toString()) ?? 0; diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index e9ce5ec4..54d2e4c5 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -400,6 +400,12 @@ class _PartDisplayState extends RefreshableState { fields["part"]["hidden"] = true; + int? default_location = part.defaultLocation; + + if (default_location != null) { + fields["location"]["value"] = default_location; + } + InvenTreeStockItem().createForm( context, L10().stockItemCreate,