why my coupon_code is not shown in order 'page

Viewed 17

Anyone guide why my copoun_obj.save() is not shown in order (order.coupon_code = copoun_obj): Basically, i applied coupon_code and it's showing on cart page but I'm not able to get the same coupon on order page and stuck to res1olve that thing 'plz anoyone guide me.

IN this i can save my copoun_obj.save() and is shown on cart page but i see s1ame thing on order page it does not show me disount coupon

def applyCoupon(request):
    copoun = request.GET.get('coupon')
    print("copun",copoun)
    #validating order and coupon
    
    if not request.user.is_authenticated:
        # Guest Part
        
        try:
            copoun_obj = CouponCode.objects.get(code=copoun)
        except:
            return JsonResponse(status=400,data={'message':'Coupon is not applicable'})    
        
        copoun_obj = CouponCode.objects.get(code=copoun)
        return JsonResponse(status=200,data={'message':'Coupon Applied','percentage':copoun_obj.percentage,'coupon_code':copoun_obj.code})    
        
    
    validateOrder(request)
    validateCopoun(request,copoun)
    
     
    try:
        copoun_obj = CouponCode.objects.get(code=copoun)
    except:
        return JsonResponse(status=400,data={'message':'Coupon is not applicable'})    
    
    print('hhh',copoun_obj.code)
    order = Order.objects.get(user=request.user,ordered=False)
    if copoun_obj.general:
        if copoun_obj.general != True:
            return JsonResponse(status=400,data={'message':'Coupon is not applicable'})  
        else:
            copoun_obj.general == True
            copoun_obj.save()
            print('---- fal-gen',copoun_obj)
    
            return JsonResponse(status=200,data={'message':'Coupon Applied gen','percentage':copoun_obj.percentage})
    # ------------ One Time Coupon ------------
    elif copoun_obj.one_time:
        if copoun_obj.one_time != True and copoun_obj.general != True:
            # if copoun_obj.one_time != True:
                return JsonResponse(status=400,data={'message':'Coupon is not 23 applicable'})  
        
        elif copoun_obj.one_time == True:
            copoun_obj.one_time = False
            

            copoun_obj.save()
            print('---- fal',copoun_obj)
    
            return JsonResponse(status=200,data={'message':'Coupon Applied Good','percentage':copoun_obj.percentage})               
    
    
    
    
    # ------------ One User  One Time ------------

    elif UserCoupon.objects.filter(code=copoun_obj.code , is_user = request.user , is_used = True).exists():
        return JsonResponse(status=403,data={'message':'Coupon not Applied','percentage':copoun_obj.percentage})
    elif request.user == None:
              return JsonResponse(status=403,data={'message':'Please Login First'})
    else:
        print('sadasf')
        UserCoupon.objects.create(code=copoun_obj.code , is_user = request.user , is_used = True, percentage=copoun_obj.percentage)
        return JsonResponse(status=200,data={'message':'Coupon Applied','percentage':copoun_obj.percentage})

    if  order.coupon_code:
        return JsonResponse(status=400,data={'message':'Coupon already applied'})    

    order = Order.objects.get(user=request.user,ordered=False)
    # copoun_obj = fponCode.objects.get()
    order.coupon_code = copoun_obj
    order.save()
    return JsonResponse(status=200,data={'message':'Coupon Applied','percentage':copoun_obj.percentage})    
0 Answers
Related