From 4191a043b271a6b772683404a3faca15521b17ae Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 9 Mar 2022 14:57:57 +1100 Subject: [PATCH 1/3] Add "exclude_location" to build order auto-allocation --- InvenTree/InvenTree/version.py | 5 ++++- InvenTree/build/models.py | 6 ++++++ InvenTree/build/serializers.py | 11 +++++++++++ InvenTree/templates/js/translated/build.js | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index 5a6e213443..e040b8fcc3 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -12,11 +12,14 @@ import common.models INVENTREE_SW_VERSION = "0.7.0 dev" # InvenTree API version -INVENTREE_API_VERSION = 29 +INVENTREE_API_VERSION = 30 """ Increment this API version number whenever there is a significant change to the API that any clients need to know about +v30 -> 2022-03-09 + - Adds "exclude_location" field to BuildAutoAllocation API endpoint + v29 -> 2022-03-08 - Adds "scheduling" endpoint for predicted stock scheduling information diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index d58180356e..9ba348b0b4 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -842,6 +842,7 @@ class Build(MPTTModel, ReferenceIndexingMixin): """ location = kwargs.get('location', None) + exclude_location = kwargs.get('exclude_location', None) interchangeable = kwargs.get('interchangeable', False) substitutes = kwargs.get('substitutes', True) @@ -875,6 +876,11 @@ class Build(MPTTModel, ReferenceIndexingMixin): sublocations = location.get_descendants(include_self=True) available_stock = available_stock.filter(location__in=[loc for loc in sublocations]) + if exclude_location: + # Exclude any stock items from the provided location + sublocations = exclude_location.get_descendants(include_self=True) + available_stock = available_stock.exclude(location__in=[loc for loc in sublocations]) + """ Next, we sort the available stock items with the following priority: 1. Direct part matches (+1) diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index ba43a079ff..4b55182563 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -717,6 +717,7 @@ class BuildAutoAllocationSerializer(serializers.Serializer): class Meta: fields = [ 'location', + 'exclude_location', 'interchangeable', 'substitutes', ] @@ -730,6 +731,15 @@ class BuildAutoAllocationSerializer(serializers.Serializer): help_text=_('Stock location where parts are to be sourced (leave blank to take from any location)'), ) + exclude_location = serializers.PrimaryKeyRelatedField( + queryset=StockLocation.objects.all(), + many=False, + allow_null=True, + required=False, + label=_('Exclude Location'), + help_text=_('Exclude stock items from this selected location'), + ) + interchangeable = serializers.BooleanField( default=False, label=_('Interchangeable Stock'), @@ -750,6 +760,7 @@ class BuildAutoAllocationSerializer(serializers.Serializer): build.auto_allocate_stock( location=data.get('location', None), + exclude_location=data.get('exclude_location', None), interchangeable=data['interchangeable'], substitutes=data['substitutes'], ) diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index 8a894189e8..86796520c2 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -1876,6 +1876,7 @@ function autoAllocateStockToBuild(build_id, bom_items=[], options={}) { location: { value: options.location, }, + exclude_location: {}, interchangeable: { value: true, }, From 4cd41bd0a3f3b474ab1402114a5d0754ca79c740 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 9 Mar 2022 15:23:23 +1100 Subject: [PATCH 2/3] Display "loading" until allocations loaded --- InvenTree/InvenTree/version.py | 1 + InvenTree/build/api.py | 1 + InvenTree/templates/js/translated/build.js | 24 +++++++++++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index e040b8fcc3..19373e930c 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -19,6 +19,7 @@ Increment this API version number whenever there is a significant change to the v30 -> 2022-03-09 - Adds "exclude_location" field to BuildAutoAllocation API endpoint + - Allows BuildItem API endpoint to be filtered by BomItem relation v29 -> 2022-03-08 - Adds "scheduling" endpoint for predicted stock scheduling information diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index 114268fa2b..33f3f4ab36 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -461,6 +461,7 @@ class BuildItemList(generics.ListCreateAPIView): filter_fields = [ 'build', 'stock_item', + 'bom_item', 'install_into', ] diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index 86796520c2..629c61b856 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -1219,6 +1219,18 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { $(table).bootstrapTable('updateByUniqueId', key, tableRow, true); } + // Update any rows which we did not receive allocation information for + var td = $(table).bootstrapTable('getData'); + + td.forEach(function(tableRow) { + if (tableRow.allocations == null) { + + tableRow.allocations = []; + + $(table).bootstrapTable('updateByUniqueId', tableRow.pk, tableRow, true); + } + }); + // Update the progress bar for this build output var build_progress = $(`#output-progress-${outputId}`); @@ -1419,15 +1431,17 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { formatter: function(value, row) { var allocated = 0; - if (row.allocations) { + if (row.allocations != null) { row.allocations.forEach(function(item) { allocated += item.quantity; }); + + var required = requiredQuantity(row); + + return makeProgressBar(allocated, required); + } else { + return `{% trans "Loading" %}`; } - - var required = requiredQuantity(row); - - return makeProgressBar(allocated, required); }, sorter: function(valA, valB, rowA, rowB) { // Custom sorting function for progress bars From cf2c07895258c7ad8f9326e8d8ccbf0accb36d55 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 9 Mar 2022 15:27:44 +1100 Subject: [PATCH 3/3] Add spinning logo --- InvenTree/templates/js/translated/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index 629c61b856..5b416b4d22 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -1440,7 +1440,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { return makeProgressBar(allocated, required); } else { - return `{% trans "Loading" %}`; + return `{% trans "loading" %}...`; } }, sorter: function(valA, valB, rowA, rowB) {