mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 12:05:53 +00:00
Now processing currencies
This commit is contained in:
@ -368,11 +368,13 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
|
||||
validated = serializers.BooleanField(read_only=True, source='is_line_valid')
|
||||
|
||||
purchase_price_min = MoneyField(max_digits=10, decimal_places=4, read_only=True)
|
||||
purchase_price_min = MoneyField(max_digits=10, decimal_places=6, read_only=True)
|
||||
|
||||
purchase_price_max = MoneyField(max_digits=10, decimal_places=4, read_only=True)
|
||||
|
||||
purchase_price_avg = MoneyField(max_digits=10, decimal_places=4, read_only=True)
|
||||
purchase_price_max = MoneyField(max_digits=10, decimal_places=6, read_only=True)
|
||||
|
||||
purchase_price_avg = serializers.SerializerMethodField()
|
||||
|
||||
purchase_price_range = serializers.SerializerMethodField()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# part_detail and sub_part_detail serializers are only included if requested.
|
||||
@ -401,6 +403,38 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
queryset = queryset.prefetch_related('sub_part__supplier_parts__pricebreaks')
|
||||
return queryset
|
||||
|
||||
def get_purchase_price_range(self, obj):
|
||||
""" Return purchase price range """
|
||||
|
||||
if obj.purchase_price_min and not obj.purchase_price_max:
|
||||
# Get price range
|
||||
purchase_price_range = str(obj.purchase_price_max)
|
||||
elif not obj.purchase_price_min and obj.purchase_price_max:
|
||||
# Get price range
|
||||
purchase_price_range = str(obj.purchase_price_max)
|
||||
elif obj.purchase_price_min and obj.purchase_price_max:
|
||||
# Get price range
|
||||
if obj.purchase_price_min >= obj.purchase_price_max:
|
||||
# If min > max: use min only
|
||||
purchase_price_range = str(obj.purchase_price_min)
|
||||
else:
|
||||
purchase_price_range = str(obj.purchase_price_min) + " - " + str(obj.purchase_price_max)
|
||||
else:
|
||||
purchase_price_range = '-'
|
||||
|
||||
return purchase_price_range
|
||||
|
||||
def get_purchase_price_avg(self, obj):
|
||||
""" Return purchase price average """
|
||||
|
||||
if obj.purchase_price_avg:
|
||||
# Get string representation of price average
|
||||
purchase_price_avg = str(obj.purchase_price_avg)
|
||||
else:
|
||||
purchase_price_avg = '-'
|
||||
|
||||
return purchase_price_avg
|
||||
|
||||
class Meta:
|
||||
model = BomItem
|
||||
fields = [
|
||||
@ -420,6 +454,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
'purchase_price_min',
|
||||
'purchase_price_max',
|
||||
'purchase_price_avg',
|
||||
'purchase_price_range',
|
||||
]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user