Ejemplo n.º 1
0
def return_add_orders_admin(request):
    perm = general_methods.control_access(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')
    kargo = float(Settings.objects.filter(name='kargo')[0].value)

    order_form = OrderFormAdmin(instance=Profile.objects.get(
        user=request.user))
    products = Product.objects.all()
    current_user = request.user
    profile = Profile.objects.get(user=current_user)

    if request.method == 'POST':

        order_form = OrderFormAdmin(request.POST)

        if order_form.is_valid():

            total_price = 0

            products_quantity = order_form.cleaned_data['droptxt']

            products_quantity = products_quantity.split(',')

            order_product_card = []

            order = Order(profile=order_form.cleaned_data['profile'],
                          city=order_form.cleaned_data['city'],
                          district=order_form.cleaned_data['district'],
                          address=order_form.cleaned_data['address'],
                          payment_type=order_form.cleaned_data['payment_type'],
                          isContract=order_form.cleaned_data['isContract'],
                          otherAddress=request.POST['diger_adres'],
                          companyInfo=request.POST['kurumsal_bilgi'])
            order.isContract = order_form.cleaned_data['isContract']
            order.save()

            for products_q in products_quantity:
                product = products_q.split('x')
                prod = Product.objects.get(id=int(product[1].strip()))
                orderProduct = OrderProduct(order=order,
                                            product=prod,
                                            quantity=int(product[0].strip()))
                orderProduct.save()
                order_product_card.append(orderProduct)

                total_price = total_price + (int(product[0].strip()) *
                                             prod.price)
            if order.cargo.status:
                if total_price >= order.cargo.lower_limit:
                    order.totalPrice = total_price

                else:
                    # order.totalPrice = float(total_price) + kargo
                    order.totalPrice = float(total_price) + float(
                        order.cargo.price)

                    order.save()

            # order.product.add(order_form.cleaned_data['product'])

            order.order_situations.add(
                OrderSituations.objects.get(name='Ödeme Bekliyor'))

            order.save()
            if order.payment_type == 'Havale/EFT':
                messages.success(request, 'Sipariş başarıyla eklendi.')
                return redirect('inoks:havale-eft-bilgi', siparis=order.id)

            else:

                messages.success(request, 'Sipariş başarıyla eklendi.')
                return redirect('inoks:odeme-yap', siparis=order.id)

        else:

            messages.warning(request, 'Alanları Kontrol Ediniz')

    return render(
        request, 'siparisler/siparis-ekle.html', {
            'order_form': order_form,
            'products': products,
            'profile': profile,
            'kargo': kargo
        })
Ejemplo n.º 2
0
def return_add_orders_from_cart(request):
    perm = general_methods.control_access(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')
    kargo = float(Settings.objects.filter(name='kargo')[0].value)
    products = Product.objects.all()
    current_user = request.user
    profile = Profile.objects.get(user=current_user)
    order_form = OrderForm(
        initial={
            'address': profile.address,
            'city': profile.city,
            'district': profile.district,
            'guest_user': None
        })
    order_form.fields['city'].queryset = City.objects.filter(
        id=profile.city_id)

    myDict = dict(request.GET)
    urun_miktar = []
    urun_miktar_2 = []
    myDict2 = dict()

    for key in myDict:
        if key.startswith('cust'):
            pickup_dict = dict()
            x = myDict[key][0].split("&")
            x = CartObject(product_id=x[0], quantity=x[1])
            urun_miktar.append(x)
            pickup_dict['product_id'] = x.product_id
            pickup_dict['quantity'] = x.quantity
            urun_miktar_2.append(pickup_dict)

    myDict2['deneme'] = urun_miktar
    serializer = CartSerializer(urun_miktar, many=True)
    data = json.dumps(serializer.data)
    # data = serializers.serialize('json', myDict2)
    # serializer = CartSerializer(urun_miktar, many=True)

    # data = serializer.data

    if request.method == 'POST':

        order_form = OrderForm(request.POST)

        if order_form.is_valid():

            total_price = 0

            products_quantity = order_form.cleaned_data['droptxt']

            products_quantity = products_quantity.split(',')

            order_product_card = []

            order = Order(profile=profile,
                          city=order_form.cleaned_data['city'],
                          district=order_form.cleaned_data['district'],
                          address=order_form.cleaned_data['address'],
                          payment_type=order_form.cleaned_data['payment_type'],
                          isContract=order_form.cleaned_data['isContract'],
                          otherAddress=request.POST['diger_adres'],
                          companyInfo=request.POST['kurumsal_bilgi'])
            order.isContract = order_form.cleaned_data['isContract']
            order.save()

            for products_q in products_quantity:
                product = products_q.split('x')
                prod = Product.objects.get(id=int(product[1].strip()))
                orderProduct = OrderProduct(order=order,
                                            product=prod,
                                            quantity=int(product[0].strip()))
                orderProduct.save()
                order_product_card.append(orderProduct)

                total_price = total_price + (int(product[0].strip()) *
                                             prod.price)

            if total_price >= 150:
                order.totalPrice = total_price
            else:
                order.totalPrice = float(total_price) + kargo

            order.save()

            # order.product.add(order_form.cleaned_data['product'])

            order.order_situations.add(
                OrderSituations.objects.get(name='Ödeme Bekliyor'))

            order.save()

            if order.payment_type == 'Havale/EFT':
                messages.success(request, 'Sipariş başarıyla eklendi.')
                return redirect('inoks:havale-eft-bilgi', siparis=order.id)

            else:

                messages.success(request, 'Sipariş başarıyla eklendi.')
                return redirect('inoks:odeme-yap', siparis=order.id)

        else:

            messages.warning(request, 'Alanları Kontrol Ediniz')

    return render(
        request, 'siparisler/siparis-ekle.html', {
            'order_form': order_form,
            'products': products,
            'product_array': data,
            'profile': profile,
            'kargo': kargo
        })