Fix order link in BillRecordSerializer

This commit is contained in:
fnux 2020-03-06 09:32:25 +01:00
parent 4016c28c5f
commit c41b55573a
2 changed files with 23 additions and 24 deletions

View file

@ -47,27 +47,6 @@ class CreatePaymentMethodSerializer(serializers.ModelSerializer):
model = PaymentMethod
fields = ['source', 'description', 'primary', 'credit_card']
###
# Bills
# TODO: remove magic numbers for decimal fields
class BillRecordSerializer(serializers.Serializer):
order = serializers.CharField()
description = serializers.CharField()
recurring_period = serializers.CharField()
recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2)
recurring_count = serializers.DecimalField(max_digits=10, decimal_places=2)
one_time_price = serializers.DecimalField(max_digits=10, decimal_places=2)
amount = serializers.DecimalField(max_digits=10, decimal_places=2)
class BillSerializer(serializers.ModelSerializer):
records = BillRecordSerializer(many=True, read_only=True)
class Meta:
model = Bill
fields = ['owner', 'total', 'due_date', 'creation_date',
'starting_date', 'ending_date', 'records', 'final']
###
# Orders & Products.
@ -83,3 +62,26 @@ class OrderSerializer(serializers.ModelSerializer):
model = Order
fields = ['uuid', 'creation_date', 'starting_date', 'ending_date',
'bill', 'recurring_period', 'records', 'recurring_price', 'one_time_price']
###
# Bills
# TODO: remove magic numbers for decimal fields
class BillRecordSerializer(serializers.Serializer):
order = serializers.HyperlinkedRelatedField(
view_name='order-detail',
read_only=True)
description = serializers.CharField()
recurring_period = serializers.CharField()
recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2)
recurring_count = serializers.DecimalField(max_digits=10, decimal_places=2)
one_time_price = serializers.DecimalField(max_digits=10, decimal_places=2)
amount = serializers.DecimalField(max_digits=10, decimal_places=2)
class BillSerializer(serializers.ModelSerializer):
records = BillRecordSerializer(many=True, read_only=True)
class Meta:
model = Bill
fields = ['owner', 'total', 'due_date', 'creation_date',
'starting_date', 'ending_date', 'records', 'final']

View file

@ -34,9 +34,6 @@ class BillViewSet(viewsets.ReadOnlyModelViewSet):
def get_queryset(self):
return Bill.objects.filter(owner=self.request.user)
def unpaid(self, request):
return Bill.objects.filter(owner=self.request.user, paid=False)
class PaymentViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = PaymentSerializer
permission_classes = [permissions.IsAuthenticated]