mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added purchase price range and average to BOM items/view
This commit is contained in:
parent
a1fa3315b1
commit
f2e9f58f1b
@ -7,7 +7,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from django.http import JsonResponse
|
||||
from django.db.models import Q, F, Count
|
||||
from django.db.models import Q, F, Count, Min, Max, Avg
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from rest_framework import status
|
||||
@ -877,6 +877,13 @@ class BomList(generics.ListCreateAPIView):
|
||||
else:
|
||||
queryset = queryset.exclude(pk__in=pks)
|
||||
|
||||
# Annotate with purchase prices
|
||||
queryset = queryset.annotate(
|
||||
purchase_price_min=Min('sub_part__stock_items__purchase_price'),
|
||||
purchase_price_max=Max('sub_part__stock_items__purchase_price'),
|
||||
purchase_price_avg=Avg('sub_part__stock_items__purchase_price'),
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
filter_backends = [
|
||||
|
@ -367,6 +367,12 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
|
||||
validated = serializers.BooleanField(read_only=True, source='is_line_valid')
|
||||
|
||||
purchase_price_min = serializers.FloatField()
|
||||
|
||||
purchase_price_max = serializers.FloatField()
|
||||
|
||||
purchase_price_avg = serializers.FloatField()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# part_detail and sub_part_detail serializers are only included if requested.
|
||||
# This saves a bunch of database requests
|
||||
@ -410,6 +416,9 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
'sub_part_detail',
|
||||
# 'price_range',
|
||||
'validated',
|
||||
'purchase_price_min',
|
||||
'purchase_price_max',
|
||||
'purchase_price_avg',
|
||||
]
|
||||
|
||||
|
||||
|
@ -243,6 +243,35 @@ function loadBomTable(table, options) {
|
||||
}
|
||||
});
|
||||
|
||||
cols.push(
|
||||
{
|
||||
field: 'purchase_price_range',
|
||||
title: '{% trans "Purchase Price Range" %}',
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
var purchase_price_range = 0;
|
||||
|
||||
if (row.purchase_price_min > 0) {
|
||||
if (row.purchase_price_min >= row.purchase_price_max) {
|
||||
purchase_price_range = row.purchase_price_min;
|
||||
} else {
|
||||
purchase_price_range = row.purchase_price_min + " - " + row.purchase_price_max;
|
||||
}
|
||||
}
|
||||
|
||||
return purchase_price_range;
|
||||
},
|
||||
});
|
||||
|
||||
cols.push(
|
||||
{
|
||||
field: 'purchase_price_avg',
|
||||
title: '{% trans "Purchase Price Average" %}',
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
// TODO - Re-introduce the pricing column at a later stage,
|
||||
|
Loading…
Reference in New Issue
Block a user