InvenTree/InvenTree/company/serializers.py

96 lines
2.3 KiB
Python
Raw Normal View History

2019-04-27 15:09:48 +00:00
"""
2019-04-27 12:18:07 +00:00
JSON serializers for Company app
"""
2017-04-14 04:45:17 +00:00
from rest_framework import serializers
from .models import Company
from .models import SupplierPart, SupplierPriceBreak
from part.serializers import PartBriefSerializer
2017-04-14 04:45:17 +00:00
2018-04-23 11:18:35 +00:00
class CompanyBriefSerializer(serializers.ModelSerializer):
2019-04-27 12:18:07 +00:00
""" Serializer for Company object (limited detail) """
url = serializers.CharField(source='get_absolute_url', read_only=True)
class Meta:
model = Company
fields = [
'pk',
'url',
'name'
]
2019-04-13 23:30:45 +00:00
class CompanySerializer(serializers.ModelSerializer):
2019-04-27 12:18:07 +00:00
""" Serializer for Company object (full detail) """
2017-04-14 04:45:17 +00:00
2018-05-02 13:17:24 +00:00
url = serializers.CharField(source='get_absolute_url', read_only=True)
part_count = serializers.CharField(read_only=True)
2018-05-02 13:17:24 +00:00
2017-04-14 04:45:17 +00:00
class Meta:
2018-04-18 23:01:07 +00:00
model = Company
fields = [
'pk',
'url',
'name',
'description',
'website',
'name',
'phone',
'address',
'email',
'contact',
'URL',
'image',
'notes',
'is_customer',
'is_supplier',
'part_count'
]
class SupplierPartSerializer(serializers.ModelSerializer):
""" Serializer for SupplierPart object """
url = serializers.CharField(source='get_absolute_url', read_only=True)
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_image_url', read_only=True)
pricing = serializers.CharField(source='unit_pricing', read_only=True)
class Meta:
model = SupplierPart
fields = [
'pk',
'url',
'part',
'part_detail',
'supplier',
'supplier_name',
'supplier_logo',
'SKU',
'manufacturer',
'MPN',
'URL',
'pricing',
]
class SupplierPriceBreakSerializer(serializers.ModelSerializer):
""" Serializer for SupplierPriceBreak object """
class Meta:
model = SupplierPriceBreak
fields = [
'pk',
'part',
'quantity',
'cost'
]