Exemplo n.º 1
0
 def create(self, validated_data):
     order = Order()
     setattr(order, 'tel_number', validated_data['tel_number'])
     setattr(order, 'address', validated_data['address'])
     order.save()
     for product in validated_data['order_products']:
         order_products = ProductOrder()
         setattr(order_products, 'product', product['product'])
         setattr(order_products, 'quantity', product['quantity'])
         setattr(order_products, 'order', order)
         order_products.save()
     return validated_data
Exemplo n.º 2
0
    def mutate(self, info, **kwargs):
        # print(kwargs)
        id = kwargs.get('id', None)
        type = kwargs.get('type', None)
        quantity = kwargs.get('quantity', None)

        if id:
            order = Order.objects.get(pk=id)
            if type:
                order.type = type
            if quantity:
                order.quantity = quantity
            order.save()
        else:
            user = info.context.user
            order = Order(
                type=type,
                quantity=quantity,
                user=user,
            )
            order.save()
        OnNewOrder.update("order")
        return OrderMutation(order=order)
Exemplo n.º 3
0
def checkout(request):
    if request.POST:
        ptype = request.POST['submit']
        ordid = request.POST['oid']
        order = Order.objects.get(order_id=ordid)
        order.status = Order.ORDER_STATE_PLACED
        order.payment_hash_id = 1
        order.instructions = request.POST['instruct']
        order.save()
        if ptype == "Pay Later":
            order.payment_mode_online = False
            order.save()
            return render(request, 'webapp/orderplaced.html', {})
        else:
            payment = Payment()
            payment.amount = request.POST['total_price']
            payment.save()
            order.payment_hash_id = payment.hash
            order.save()
            return render(request, 'webapp/online_pay.html', {})
    else:
        cart = request.COOKIES['cart'].split(",")
        cart = dict(Counter(cart))
        items = []
        totalprice = 0
        order = Order()

        # order.save()
        print(order.order_id)
        order.tax = 0.05 * totalprice
        order.user = Customer.objects.get(user_id=request.user.id)
        order.datetime = datetime.now()
        # order.offer = Offer.objects.get(offer_id=1)
        for x, y in cart.items():
            it = FoodItem.objects.get(food_item_id=int(x))
            print(it.name)
            item_rest = FoodRestaurant.objects.get(
                food_item_id=it.food_item_id)
            order.restaurant = Restaurant.objects.get(
                restaurant_id=item_rest.restaurant.restaurant_id)
            yu = Offer.objects.get(offer_id=Restaurant.objects.get(
                restaurant_id=item_rest.restaurant.restaurant_id).offer_id)
            print(yu.discount)
            order.offer_id = yu.offer_id
        order.payment_hash_id = 1
        order.save()
        for x, y in cart.items():
            item = []
            it = FoodItem.objects.get(food_item_id=int(x))
            print(it.name)
            item_rest = FoodRestaurant.objects.get(
                food_item_id=it.food_item_id)

            print(order.order_id)
            order_detail = OrderDetail()
            order_detail.food_item_id = it.food_item_id
            order_detail.order_id = order.order_id
            order_detail.quantity = int(y)
            order_detail.save()
            item.append(it.name)
            item.append(y)
            totalprice += item_rest.cost * y
            item.append(item_rest.cost * y)
            items.append(item)
        order.tax = int(0.05 * totalprice)
        withouttax = totalprice
        totalprice += order.tax
        totalprice -= int(yu.discount)
        if totalprice < order.tax:
            totalprice = order.tax
        order.save()

        context = {
            "items": items,
            "yu": yu,
            "totalprice": totalprice,
            "withouttax": withouttax,
            "order": order,
            "oid": order.order_id
        }
        return render(request, 'webapp/order.html', context)