src/policy/api_v1/serializers.py
def create(self, validated_data):
        """
        create method of the serializer.
        :param validated_data: data containing customer_id and policy type
        :return: returns a successfully created Quote for the customer
        """
        errors = OrderedDict()
        try:
            customer = Customer.objects.get(id=validated_data['customer']['id'])
        except Customer.DoesNotExist as exc:
            errors['customer_id'] = [ErrorDetail(string=exc, code='invalid')]

        try:
            coverage = Coverage.objects.get(type=validated_data['coverage']['type'])
        except Coverage.DoesNotExist as exc:
            errors['type'] = [ErrorDetail(string=exc, code='invalid')]

        if errors:
            raise ValidationError(errors)

        quote = Policy.objects.create(coverage=coverage, customer=customer, state='quoted')
        if quote:
            PolicyHistory.objects.create(policy=quote, state=quote.state)
        return quote

        create method of the serializer.
        :param validated_data: data containing customer_id and policy type
        :return: returns a successfully created Quote for the customer
        
create method of the serializer.
create method of the serializer .
def create(self, validated_data):
        errors = OrderedDict()
        try:
            customer = Customer.objects.get(id=validated_data['customer']['id'])
        except Customer.DoesNotExist as exc:
            errors['customer_id'] = [ErrorDetail(string=exc, code='invalid')]
        try:
            coverage = Coverage.objects.get(type=validated_data['coverage']['type'])
        except Coverage.DoesNotExist as exc:
            errors['type'] = [ErrorDetail(string=exc, code='invalid')]
        if errors:
            raise ValidationError(errors)
        quote = Policy.objects.create(coverage=coverage, customer=customer, state='quoted')
        if quote:
            PolicyHistory.objects.create(policy=quote, state=quote.state)
        return quote
def create ( self , validated_data ) : errors = OrderedDict ( ) try : customer = Customer . objects . get ( id = validated_data [ 'customer' ] [ 'id' ] ) except Customer . DoesNotExist as exc : errors [ 'customer_id' ] = [ ErrorDetail ( string = exc , code = 'invalid' ) ] try : coverage = Coverage . objects . get ( type = validated_data [ 'coverage' ] [ 'type' ] ) except Coverage . DoesNotExist as exc : errors [ 'type' ] = [ ErrorDetail ( string = exc , code = 'invalid' ) ] if errors : raise ValidationError ( errors ) quote = Policy . objects . create ( coverage = coverage , customer = customer , state = 'quoted' ) if quote : PolicyHistory . objects . create ( policy = quote , state = quote . state ) return quote
create method of the serializer.
create method of the serializer .
"""
        create method of the serializer.
        :param validated_data: data containing customer_id and policy type
        :return: returns a successfully created Quote for the customer
        """
returns a successfully created Quote for the customer
returns a successfully created Quote for the customer
self
validated_data
data containing customer_id and policy type
data containing customer_id and policy type