Django добавление probelm в реальном времени

это html include, который добавляет товар и делает мульти добавление случайным, один раз он не делает дубликат, и один раз работает нормально .

это views.py

def add_item_resturant(request,pk):
    print(f"This is request.POST: {request.POST}")
    current_user=request.user
    customer=Customer.objects.get(customer_name=request.POST['customer'])
    CstPoints=customer.customer_Points
    user_branch=request.user.user_profile.user_branch
current_order=OrderDetail.objects.select_related('order_order').select_related('order_product_name').filter(order_order__order_progress="In Progress",order_order__order_who_created=current_user)
    current_product=BrancheProductQuantity.objects.get(id=pk)
    branch_tax=current_product.bpq_branch_name.branch_Tax
    real_quantity=current_product.bpq_real_quantity
    sell_price=current_product.bpq_product_sell_price
    returned_order=Order.objects.get(order_who_created=current_user,order_progress="In Progress")
    get_quantity = request.POST['quantity']
    if float(real_quantity) - float(get_quantity) < 0 :
        messages.warning(request,"Product Quantity is Error and the Quantity of it=" + str(real_quantity) +"and you enter" + get_quantity)
        return redirect("orders:add_resturant_order")
    if request.method =="POST" :
        order_detail , created =OrderDetail.objects.get_or_create(
            order_order = returned_order,
            order_product_name = current_product)
        qfloat=float(get_quantity)
        sfloat=float(sell_price)
        total_item=float(qfloat*sfloat)
        tax=(total_item*branch_tax/100)
        price_iclude_tax=tax+total_item
        order_detail.order_tax_value=float(tax)
        order_detail.order_product_name=current_product
        order_detail.order_product_price=current_product.bpq_product_sell_price
        order_detail.order_product_quantity=float(get_quantity)
        order_detail.order_detail_total=float(total_item)
        order_detail.total= float(price_iclude_tax)
        order_detail.order_biller_user = str(current_user)
        order_detail.order_branch = str(user_branch)
        order_detail.save()
    final_total_value=current_order.aggregate(Sum('total'))['total__sum']
    final_tax_value=current_order.aggregate(Sum('order_tax_value'))['order_tax_value__sum']
    full_sub_total=current_order.aggregate(Sum('order_detail_total'))['order_detail_total__sum']
    returned_order=returned_order.refresh_from_db()
    html = render_to_string('include/add_item_resturant.html',{'CstPoints':CstPoints,'final_total_value':final_total_value,'final_tax_value':final_tax_value,'full_sub_total':full_sub_total,'returned_order':returned_order,'order_detailed':current_order,  request:request})
    return JsonResponse({'result':html})

введите описание изображения здесь

Я хочу решить эту проблему она делает добавление продукта дважды и может быть 3 или 4 раза как показано на странице я не знаю почему эта проблема появляется.

Вернуться на верх