From 9baf856d755314858db8556721c3679f6e673da6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 1 Jun 2021 16:14:26 +1000 Subject: [PATCH] Fixes for build item allocation rendering --- InvenTree/InvenTree/version.py | 6 +++++- InvenTree/build/models.py | 13 +++++++++++++ InvenTree/build/serializers.py | 6 ++++-- InvenTree/templates/js/build.js | 12 +++++++++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index a736bfe6a1..7b8546b1c2 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -16,9 +16,13 @@ Increment thi API version number whenever there is a significant change to the A v3 -> 2021-05-22: - The updated StockItem "history tracking" now uses a different interface +v4 -> 2021-06-01 + - BOM items can now accept "variant stock" to be assigned against them + - Many slight API tweaks were needed to get this to work properly! + """ -INVENTREE_API_VERSION = 3 +INVENTREE_API_VERSION = 4 def inventreeInstanceName(): diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index afe7f335e4..031eb09303 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -30,6 +30,7 @@ from InvenTree.models import InvenTreeAttachment import common.models import InvenTree.fields +import InvenTree.helpers from stock import models as StockModels from part import models as PartModels @@ -1280,6 +1281,18 @@ class BuildItem(models.Model): # Simply remove the items from stock item.take_stock(self.quantity, user) + def getStockItemThumbnail(self): + """ + Return qualified URL for part thumbnail image + """ + + if self.stock_item and self.stock_item.part: + return InvenTree.helpers.getMediaUrl(self.stock_item.part.image.thumbnail.url) + elif self.bom_item and self.stock_item.sub_part: + return InvenTree.helpers.getMediaUrl(self.bom_item.sub_part.image.thumbnail.url) + else: + return InvenTree.helpers.getBlankThumbnail() + build = models.ForeignKey( Build, on_delete=models.CASCADE, diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index 550a3c3a85..629422f6e5 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -97,9 +97,10 @@ class BuildSerializer(InvenTreeModelSerializer): class BuildItemSerializer(InvenTreeModelSerializer): """ Serializes a BuildItem object """ + bom_part = serializers.IntegerField(source='bom_item.sub_part.pk', read_only=True) part = serializers.IntegerField(source='stock_item.part.pk', read_only=True) part_name = serializers.CharField(source='stock_item.part.full_name', read_only=True) - part_image = serializers.CharField(source='stock_item.part.image', read_only=True) + part_thumb = serializers.CharField(source='getStockItemThumbnail', read_only=True) stock_item_detail = StockItemSerializerBrief(source='stock_item', read_only=True) quantity = serializers.FloatField() @@ -108,11 +109,12 @@ class BuildItemSerializer(InvenTreeModelSerializer): model = BuildItem fields = [ 'pk', + 'bom_part', 'build', 'install_into', 'part', 'part_name', - 'part_image', + 'part_thumb', 'stock_item', 'stock_item_detail', 'quantity' diff --git a/InvenTree/templates/js/build.js b/InvenTree/templates/js/build.js index 0233974741..9523d24d39 100644 --- a/InvenTree/templates/js/build.js +++ b/InvenTree/templates/js/build.js @@ -372,7 +372,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { data.forEach(function(item) { // Group BuildItem objects by part - var part = item.part; + var part = item.bom_part || item.part; var key = parseInt(part); if (!(key in allocations)) { @@ -461,6 +461,16 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { data: row.allocations, showHeader: true, columns: [ + { + field: 'part', + title: '{% trans "Part" %}', + formatter: function(value, row) { + + var html = imageHoverIcon(row.part_thumb); + html += renderLink(row.part_name, `/part/${value}/`); + return html; + } + }, { width: '50%', field: 'quantity',