Fixes for build item allocation rendering

This commit is contained in:
Oliver Walters 2021-06-01 16:14:26 +10:00
parent ab16e1efc3
commit 9baf856d75
4 changed files with 33 additions and 4 deletions

View File

@ -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():

View File

@ -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,

View File

@ -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'

View File

@ -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',