Fix pricing bug

- Include BOM item pricing in API
This commit is contained in:
Oliver Walters 2019-05-18 21:43:52 +10:00
parent 2a1fd2b03b
commit 2b098942b0
3 changed files with 10 additions and 3 deletions

View File

@ -636,7 +636,7 @@ class Part(models.Model):
if min_price is None: if min_price is None:
return None return None
else: else:
return min_price * quantity return min_price
def get_max_supplier_price(self, quantity=1): def get_max_supplier_price(self, quantity=1):
""" Return the maximum price of this part from all available suppliers. """ Return the maximum price of this part from all available suppliers.
@ -662,7 +662,7 @@ class Part(models.Model):
if max_price is None: if max_price is None:
return None return None
else: else:
return max_price * quantity return max_price
def get_min_bom_price(self, quantity=1): def get_min_bom_price(self, quantity=1):
""" Return the minimum price of the BOM for this part. """ Return the minimum price of the BOM for this part.
@ -989,3 +989,8 @@ 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_info(self):
""" Return the price for this item in the BOM """
return self.sub_part.get_price_info(self.quantity)

View File

@ -108,6 +108,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_info = serializers.CharField(read_only=True)
class Meta: class Meta:
model = BomItem model = BomItem
@ -118,6 +119,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
'sub_part', 'sub_part',
'sub_part_detail', 'sub_part_detail',
'quantity', 'quantity',
'price_info',
'overage', 'overage',
'note', 'note',
] ]

View File

@ -153,7 +153,7 @@ function loadBomTable(table, options) {
); );
cols.push({ cols.push({
field: 'sub_part_detail.single_price_info', field: 'price_info',
title: 'Price', title: 'Price',
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {