diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index 70a24f0d8b..7c43d6ea2c 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -91,12 +91,10 @@ class SupplierPartList(generics.ListCreateAPIView): def get_serializer(self, *args, **kwargs): # Do we wish to include extra detail? - try: - part_detail = str2bool(self.request.GET.get('part_detail', None)) - except AttributeError: - part_detail = None - - kwargs['part_detail'] = part_detail + kwargs['part_detail'] = str2bool(self.request.query_params.get('part_detail', None)) + kwargs['supplier_detail'] = str2bool(self.request.query_params.get('supplier_detail', None)) + kwargs['manufacturer_detail'] = str2bool(self.request.query_params.get('manufacturer_detail', None)) + kwargs['context'] = self.get_serializer_context() return self.serializer_class(*args, **kwargs) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 5e59b512d1..b807d6825f 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -23,6 +23,7 @@ from markdownx.models import MarkdownxField from stdimage.models import StdImageField from InvenTree.helpers import getMediaUrl, getBlankImage, getBlankThumbnail +from InvenTree.helpers import normalize from InvenTree.fields import InvenTreeURLField, RoundingDecimalField from InvenTree.status_codes import OrderStatus from common.models import Currency @@ -352,7 +353,7 @@ class SupplierPart(models.Model): if pb_found: cost = pb_cost * quantity - return cost + self.base_cost + return normalize(cost + self.base_cost) else: return None diff --git a/InvenTree/company/serializers.py b/InvenTree/company/serializers.py index 6dbafeeea5..701c1faabf 100644 --- a/InvenTree/company/serializers.py +++ b/InvenTree/company/serializers.py @@ -17,12 +17,16 @@ class CompanyBriefSerializer(InvenTreeModelSerializer): url = serializers.CharField(source='get_absolute_url', read_only=True) + image = serializers.CharField(source='get_thumbnail_url', read_only=True) + class Meta: model = Company fields = [ 'pk', 'url', - 'name' + 'name', + 'description', + 'image', ] @@ -64,20 +68,28 @@ class SupplierPartSerializer(InvenTreeModelSerializer): part_detail = PartBriefSerializer(source='part', many=False, read_only=True) - supplier_name = serializers.CharField(source='supplier.name', read_only=True) - supplier_logo = serializers.CharField(source='supplier.get_thumbnail_url', read_only=True) + supplier_detail = CompanyBriefSerializer(source='supplier', many=False, read_only=True) + manufacturer_detail = CompanyBriefSerializer(source='manufacturer', many=False, read_only=True) pricing = serializers.CharField(source='unit_pricing', read_only=True) def __init__(self, *args, **kwargs): part_detail = kwargs.pop('part_detail', False) + supplier_detail = kwargs.pop('supplier_detail', False) + manufacturer_detail = kwargs.pop('manufacturer_detail', False) super(SupplierPartSerializer, self).__init__(*args, **kwargs) if part_detail is not True: self.fields.pop('part_detail') + if supplier_detail is not True: + self.fields.pop('supplier_detail') + + if manufacturer_detail is not True: + self.fields.pop('manufacturer_detail') + class Meta: model = SupplierPart fields = [ @@ -86,11 +98,10 @@ class SupplierPartSerializer(InvenTreeModelSerializer): 'part', 'part_detail', 'supplier', - 'supplier_name', - 'supplier_logo', + 'supplier_detail', 'SKU', 'manufacturer', - 'manufacturer_name', + 'manufacturer_detail', 'description', 'MPN', 'link', diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html index 46ec09ffc6..bb758330e1 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_part.html @@ -53,6 +53,8 @@ return { supplier: {{ company.id }}, part_detail: true, + supplier_detail: true, + manufacturer_detail: true, } }, columns: [ @@ -94,6 +96,16 @@ sortable: true, field: 'manufacturer', title: '{% trans "Manufacturer" %}', + formatter: function(value, row, index, field) { + if (value) { + var name = row.manufacturer_detail.name; + var html = imageHoverIcon(row.manufacturer_detail.image) + renderLink(name, '/company/' + value + '/'); + + return html; + } else { + return "-"; + } + } }, { sortable: true,