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
|
|
|
|
|
2018-04-23 09:36:46 +00:00
|
|
|
from .models import Company
|
2019-05-18 08:04:25 +00:00
|
|
|
from .models import SupplierPart, SupplierPriceBreak
|
|
|
|
|
2019-06-13 13:03:58 +00:00
|
|
|
from InvenTree.serializers import InvenTreeModelSerializer
|
|
|
|
|
2019-05-18 08:04:25 +00:00
|
|
|
from part.serializers import PartBriefSerializer
|
2017-04-14 04:45:17 +00:00
|
|
|
|
2018-04-23 11:18:35 +00:00
|
|
|
|
2019-06-13 13:03:58 +00:00
|
|
|
class CompanyBriefSerializer(InvenTreeModelSerializer):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" Serializer for Company object (limited detail) """
|
2018-05-02 14:47:03 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-06-13 13:03:58 +00:00
|
|
|
class CompanySerializer(InvenTreeModelSerializer):
|
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)
|
2019-05-16 12:29:39 +00:00
|
|
|
part_count = serializers.CharField(read_only=True)
|
2018-05-02 13:17:24 +00:00
|
|
|
|
2020-04-07 01:27:56 +00:00
|
|
|
image = serializers.CharField(source='get_thumbnail_url', read_only=True)
|
2019-09-02 12:06:42 +00:00
|
|
|
|
2017-04-14 04:45:17 +00:00
|
|
|
class Meta:
|
2018-04-18 23:01:07 +00:00
|
|
|
model = Company
|
2019-05-16 12:29:39 +00:00
|
|
|
fields = [
|
2019-05-22 14:31:27 +00:00
|
|
|
'pk',
|
2019-05-16 12:29:39 +00:00
|
|
|
'url',
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'website',
|
|
|
|
'name',
|
|
|
|
'phone',
|
|
|
|
'address',
|
|
|
|
'email',
|
|
|
|
'contact',
|
2020-04-06 01:36:25 +00:00
|
|
|
'link',
|
2019-05-16 12:29:39 +00:00
|
|
|
'image',
|
|
|
|
'notes',
|
|
|
|
'is_customer',
|
|
|
|
'is_supplier',
|
|
|
|
'part_count'
|
|
|
|
]
|
2019-05-18 08:04:25 +00:00
|
|
|
|
|
|
|
|
2019-06-13 13:03:58 +00:00
|
|
|
class SupplierPartSerializer(InvenTreeModelSerializer):
|
2019-05-18 08:04:25 +00:00
|
|
|
""" 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)
|
2020-04-07 01:27:56 +00:00
|
|
|
supplier_logo = serializers.CharField(source='supplier.get_thumbnail_url', read_only=True)
|
2019-05-18 08:04:25 +00:00
|
|
|
|
2019-05-22 12:11:27 +00:00
|
|
|
pricing = serializers.CharField(source='unit_pricing', read_only=True)
|
|
|
|
|
2019-05-23 12:44:37 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
|
|
|
part_detail = kwargs.pop('part_detail', False)
|
|
|
|
|
|
|
|
super(SupplierPartSerializer, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
if part_detail is not True:
|
|
|
|
self.fields.pop('part_detail')
|
|
|
|
|
2019-05-18 08:04:25 +00:00
|
|
|
class Meta:
|
|
|
|
model = SupplierPart
|
|
|
|
fields = [
|
|
|
|
'pk',
|
|
|
|
'url',
|
|
|
|
'part',
|
|
|
|
'part_detail',
|
|
|
|
'supplier',
|
|
|
|
'supplier_name',
|
|
|
|
'supplier_logo',
|
|
|
|
'SKU',
|
|
|
|
'manufacturer',
|
2019-05-24 11:33:45 +00:00
|
|
|
'description',
|
2019-05-18 08:04:25 +00:00
|
|
|
'MPN',
|
2020-04-06 01:36:25 +00:00
|
|
|
'link',
|
2019-05-22 12:11:27 +00:00
|
|
|
'pricing',
|
2019-05-18 08:04:25 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-06-13 13:03:58 +00:00
|
|
|
class SupplierPriceBreakSerializer(InvenTreeModelSerializer):
|
2019-05-18 08:04:25 +00:00
|
|
|
""" Serializer for SupplierPriceBreak object """
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SupplierPriceBreak
|
|
|
|
fields = [
|
|
|
|
'pk',
|
|
|
|
'part',
|
|
|
|
'quantity',
|
|
|
|
'cost'
|
|
|
|
]
|