Merge remote-tracking branch 'inventree/master'

This commit is contained in:
Oliver Walters 2019-05-21 16:37:16 +10:00
commit afb927258c
3 changed files with 35 additions and 2 deletions

View File

@ -933,3 +933,19 @@ class BomItem(models.Model):
base_quantity = self.quantity * build_quantity base_quantity = self.quantity * build_quantity
return base_quantity + self.get_overage_quantity(base_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)

View File

@ -122,6 +122,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
part_detail = PartBriefSerializer(source='part', many=False, read_only=True) part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
sub_part_detail = PartBriefSerializer(source='sub_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 @staticmethod
def setup_eager_loading(queryset): def setup_eager_loading(queryset):
@ -131,6 +132,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
queryset = queryset.prefetch_related('sub_part') queryset = queryset.prefetch_related('sub_part')
queryset = queryset.prefetch_related('sub_part__category') queryset = queryset.prefetch_related('sub_part__category')
queryset = queryset.prefetch_related('sub_part__stock_items') queryset = queryset.prefetch_related('sub_part__stock_items')
queryset = queryset.prefetch_related('sub_part__supplier_parts__pricebreaks')
return queryset return queryset
class Meta: class Meta:
@ -142,6 +144,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
'sub_part', 'sub_part',
'sub_part_detail', 'sub_part_detail',
'quantity', 'quantity',
'price_range',
'overage', 'overage',
'note', 'note',
] ]

View File

@ -149,8 +149,22 @@ function loadBomTable(table, options) {
return renderLink(text, row.sub_part_detail.url + "stock/"); 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 "<span class='warning-msg'>No pricing available</span>";
}
}
});
} }
// Part notes // Part notes