'DRF error [<class 'decimal.ConversionSyntax'>] when calling a function in serializer

Below is my function in django models.

 def calc_totals(self):
        self.total_net_purchase_price = F('quantity') * F('net_purchase_price')
        self.total_net_sales_price = F('quantity') * F('net_sales_price')
        self.total_gross_purchase_price = F('quantity') * F('gross_purchase_price')
        self.total_gross_sales_price = F('quantity') * F('gross_sales_price')
        self.total_net_profit = F('total_net_sales_price') - F('total_net_purchase_price')
        self.total_gross_profit = F('total_gross_sales_price') - F('total_gross_purchase_price')

When I call this function in DRF serializer:

class PZItemSerializer(CountryFieldMixin, serializers.ModelSerializer):
    class Meta:
        model = PZItem
        fields = '__all__'

    def update(self, instance, validated_data):
        instance.calc_totals()
        instance.save()
        return instance

It throws error:

[<class 'decimal.ConversionSyntax'>]

What's wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source