Esempio n. 1
0
    def put(self, request, *args, **kwargs):
        modified_order_json = request.body
        modified_order_dict = json.loads(modified_order_json)

        new_order_status = modified_order_dict["status"];
        
        order_id = self.kwargs.get('pk', None)
        order = Order.objects.get_or_none(id=order_id)

        if order:
            if new_order_status == "Cancelled" and order.status == 'P':
                OrderOperations.update_order_status(order, 'C', 'X', request.user)
                #TODO: Notify customer of order cancellation

            elif new_order_status == "Fulfilled" and order.status == 'P':
                order.date_fulfillment_actual = datetime.now()                
                OrderOperations.update_order_status(order, 'F', 'F', request.user)
                #TODO: Notify customer of order fulfillment and invite to pick up

            elif new_order_status == "Delivered" and order.status == 'F':
                order.date_delivered = datetime.now()
                OrderOperations.update_order_status(order, 'D', 'D', request.user)
                #TODO: Notify customer of order delivery/collection

            else:
                #TODO: kindly do nothing
                pass

            response = Response(OrderOperations.get_order_details(order_id), status=status.HTTP_200_OK)

        else:
            response = Response({"error": "Order not found!"}, status=status.HTTP_404_NOT_FOUND)

        return response
Esempio n. 2
0
    def get(self, request, *args, **kwargs):
        order_id = self.kwargs.get('pk', None)
        order = Order.objects.get_or_none(id=order_id)

        if order_id and order:
            order = OrderOperations.get_order_details(order_id)
            response = Response(order, status=status.HTTP_200_OK)

        else:
            response = Response({"error": "Order not found!"}, status=status.HTTP_404_NOT_FOUND)

        return response
Esempio n. 3
0
    def get(self, request, *args, **kwargs):
        order_id = self.kwargs.get('pk', None)
        order = Order.objects.get_or_none(id=order_id)

        if order_id and order:
            order = OrderOperations.get_order_details(order_id)
            response = Response(order, status=status.HTTP_200_OK)

        else:
            response = Response({"error": "Order not found!"},
                                status=status.HTTP_404_NOT_FOUND)

        return response
Esempio n. 4
0
    def put(self, request, *args, **kwargs):
        modified_order_json = request.body
        modified_order_dict = json.loads(modified_order_json)

        new_order_status = modified_order_dict["status"]

        order_id = self.kwargs.get('pk', None)
        order = Order.objects.get_or_none(id=order_id)

        if order:
            if new_order_status == "Cancelled" and order.status == 'P':
                OrderOperations.update_order_status(order, 'C', 'X',
                                                    request.user)
                #TODO: Notify customer of order cancellation

            elif new_order_status == "Fulfilled" and order.status == 'P':
                order.date_fulfillment_actual = datetime.now()
                OrderOperations.update_order_status(order, 'F', 'F',
                                                    request.user)
                #TODO: Notify customer of order fulfillment and invite to pick up

            elif new_order_status == "Delivered" and order.status == 'F':
                order.date_delivered = datetime.now()
                OrderOperations.update_order_status(order, 'D', 'D',
                                                    request.user)
                #TODO: Notify customer of order delivery/collection

            else:
                #TODO: kindly do nothing
                pass

            response = Response(OrderOperations.get_order_details(order_id),
                                status=status.HTTP_200_OK)

        else:
            response = Response({"error": "Order not found!"},
                                status=status.HTTP_404_NOT_FOUND)

        return response