def create(self, request):
        req_body = json.loads(request.body.decode())
        new_order = Order()
        new_order.customer_id = request.auth.user.customer.id
        new_order.save()

        new_orderproduct = OrderProduct()
        products = Product.objects.all()
        new_orderproduct.order_id = new_order.id
        new_orderproduct.product_id = req_body['product_id']
        new_orderproduct.save()

        serializer = OrderSerializer(new_order, context={'request': request})

        return Response(serializer.data)
    def create(self, request):
        """Handle POST operations

        Returns:
            Response -- JSON serialized Order instance
        """
        new_order = Order()

        # uncomment this line when AUTH is ready
        new_order.customer_id = request.auth.user.customer.id
        # use this line UTNIL AUTH is ready
        # new_order.customer_id = request.data["customer_id"]

        new_order.save()

        serializer = OrderSerializer(new_order, context={'request': request})

        return Response(serializer.data)
    def test_complete_order(self):
        """
        Ensure that an order is completed by adding a payment type
        """
        order = Order()
        order.customer_id = 1
        order.created_date = datetime.date.today()
        order.payment_type = None
        order.save()

        data = {"payment_type": self.payment.id}

        url = f"/orders/{order.id}"

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        test_order = Order.objects.get(pk=order.id)
        test_payment = Payment.objects.get(pk=self.payment.id)
        self.assertEqual(test_order.payment_type, test_payment)