def updateStatus_view(request, order_id): if not request.user.is_staff or not request.user.is_superuser or request.method != "POST": return HttpResponseRedirect('/404notfound/') try: order = Order.objects.get(order_id=order_id) if order.status == True: order.status = False notf = "Order #" + str(order.order_no) + " is pending." elif order.status == False: order.status = True notf = "Order #" + str(order.order_no) + " is accepted." order.save() except: messages.success(request, "Couldn't change status.") pass # SEND NOTIFICATION if order.account != None: notification = Notification() notification.account = order.account notification.content = notf notification.link = '/orders/' + order.order_id + '/' notification.save() return HttpResponseRedirect('/orders/management/')
def newOrder_view(request): template_name = 'orders/confirmed-page.html' if request.method == "POST": cartKey = request.POST['cart'] phone = request.POST['cell'] order_type = request.POST['orderType'] account = None if request.user.is_authenticated: account = Account.objects.get(user=request.user) else: qs = Account.objects.filter(phone=phone).exists() if qs: account = Account.objects.get(phone=phone) order = Order() order.account = account try: cart = Cart.objects.get(key=cartKey) cart.is_active = True cart.save() order.cart = cart except: messages.warning(request, "Order request failed! Please try again.") return HttpResponseRedirect('/restaurants/' + cart.restaurant.slug + '/') _discount = 0.00 try: dObj = Discount.objects.get(key=request.POST['promoCode']) if dObj.used == False: _discount = int( float(cart.subtotal * dObj.percentage) / 100.00) dObj.used = True dObj.save() except: pass order.name = request.POST['name'] order.phone = phone order.shipping_address = request.POST['location'] order.order_type = order_type order.payment_method = request.POST['paymentMethod'] order.expected_time = request.POST['time'] if order_type == 'home': order.cost = cart.total - _discount + 30.00 # Shipping cost else: order.cost = cart.total - _discount order.discount = _discount order.save() # SEND NOTIFICATION if account != None: notification = Notification() notification.account = account notification.content = "You order <span class='font-weight-bold'>#" + str( order.order_no ) + "</span> has been added. We will confirm it in minutes." notification.link = '/orders/' + order.order_id + '/' notification.save() return HttpResponseRedirect('/orders/' + order.order_id + '/') messages.warning(request, "Something went wrong. Please try again.") return HttpResponseRedirect('/restaurants/' + cart.restaurant.slug + '/')
def DeleteOrder_view(request, order_id): if not request.user.is_staff or not request.user.is_superuser or request.method != "POST": return HttpResponseRedirect('/404notfound/') try: order = Order.objects.get(order_id=order_id) # SEND NOTIFICATION if order.account != None: notification = Notification() notification.account = order.account notification.content = "Order #" + str(order.order_no) + " has been deleted." notification.link = '/orders/' + order.order_id + '/' notification.save() order.delete() except: messages.success(request, "Couldn't change status.") pass return HttpResponseRedirect('/orders/management/')