Exemple #1
0
def create_order(request):
    customer = request.data['customer']
    data = request.data['list']
    cost = 0
    customer = CustomerProfile.objects.filter(
        Q(customer_id=customer['customer_id']))[0]
    total_count = 0
    order = Order(customer_id=customer.pk)
    order.save()
    for p in data:
        for m in data[p]:
            price = SchemaSeries.objects.filter(name=p)[0].price
            cost += int(data[p][m]) * int(price)
            total_count += int(data[p][m])
            new_melody = ShopItem(melody_name=m,
                                  order=order,
                                  series=p,
                                  price=int(price),
                                  ordered_count=int(data[p][m]),
                                  order_admin_verified_count=int(data[p][m]),
                                  sell_admin_verified_count=int(data[p][m]))
            new_melody.save(force_insert=True)
    order.status = Order.ORDER_ADMIN
    order.cost = cost
    order.last_change_date = timezone.now()
    order.order_id = get_new_order_id()
    order.save()
    return Response()
Exemple #2
0
    def post(self, request, **kwargs):
        order = Order()
        order.product_name = request.session['productTitle']
        order.product_url = request.session['url']
        order.fee = float(request.session['productCost'])*0.15
        order.status = "Finding a traveller"
        order.creation_time = timezone.now()
        order.save()

        user = User.objects.get(pk=request.user.pk)

        customer = Customer()
        customer.order = order
        customer.user = user
        customer.city = request.session['city']
        customer.save()

        messages.info(request, "Payment successful! We'll notify you when we find a traveller for you!")
        return redirect('HomePage')