diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 1d1d1b4fec..2cfb37d3e3 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -933,3 +933,19 @@ class BomItem(models.Model): base_quantity = self.quantity * build_quantity return base_quantity + self.get_overage_quantity(base_quantity) + + @property + def price_range(self): + """ Return the price-range for this BOM item. """ + + prange = self.sub_part.get_price_range(self.quantity) + + if prange is None: + return prange + + pmin, pmax = prange + + if pmin == pmax: + return str(pmin) + + return "{pmin} to {pmax}".format(pmin=pmin, pmax=pmax) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 213cb9c75e..cb7cc8bda3 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -122,6 +122,7 @@ class BomItemSerializer(InvenTreeModelSerializer): part_detail = PartBriefSerializer(source='part', many=False, read_only=True) sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True) + price_range = serializers.CharField(read_only=True) @staticmethod def setup_eager_loading(queryset): @@ -131,6 +132,7 @@ class BomItemSerializer(InvenTreeModelSerializer): queryset = queryset.prefetch_related('sub_part') queryset = queryset.prefetch_related('sub_part__category') queryset = queryset.prefetch_related('sub_part__stock_items') + queryset = queryset.prefetch_related('sub_part__supplier_parts__pricebreaks') return queryset class Meta: @@ -142,6 +144,7 @@ class BomItemSerializer(InvenTreeModelSerializer): 'sub_part', 'sub_part_detail', 'quantity', + 'price_range', 'overage', 'note', ] diff --git a/InvenTree/static/script/inventree/bom.js b/InvenTree/static/script/inventree/bom.js index 6ff81de4fc..a995fe0ed8 100644 --- a/InvenTree/static/script/inventree/bom.js +++ b/InvenTree/static/script/inventree/bom.js @@ -149,8 +149,22 @@ function loadBomTable(table, options) { return renderLink(text, row.sub_part_detail.url + "stock/"); } - } - ); + }); + + cols.push( + { + field: 'price_range', + title: 'Price', + sortable: true, + formatter: function(value, row, index, field) { + if (value) { + return value; + } else { + return "No pricing available"; + } + } + }); + } // Part notes