Example #1
0
def changeOrderItemStatus(request):
    data = request.POST
    pk = data['pk'];
    instock = int(data['instock']);
    orderitem = OrderItem.objects.get(pk = pk);
    order = orderitem.order
    orderitem.status = 'I'

    if instock < orderitem.quantity:
        new_order_item = OrderItem()
        new_order_item.quantity = orderitem.quantity - instock
        new_order_item.category = orderitem.category
        new_order_item.description = orderitem.description
        new_order_item.status = 'P'
        new_order_item.order = orderitem.order
        new_order_item.save()
        inform_purchase_agent(subject='سفارش نیازمند خرید است',message=render_to_string('mail/buy_orderitem.html',{'orderitem' : new_order_item}))

    if instock == 0:
        orderitem.delete()
    else:
        orderitem.quantity = instock
        orderitem.save()
        inner_q = Good.objects.filter(category=orderitem.category,user=None)[:instock]
        Good.objects.filter(pk__in = inner_q).update(user=order.user)
        inform_user(user=order.user, message=render_to_string('mail/orderitem_available.html', {'orderitem': orderitem}),
                    subject='سفارش شما در انبار موجود است')
    #check and change the status of the order
    if OrderItem.objects.filter(order= order,status='N').count() == 0:
        return HttpResponse('order_changed')
    return HttpResponse("success")
Example #2
0
def addOrder(request):
    c = request.POST
    tableData = json.loads( c['tableData']);

    today = jDateField();
    today = today.to_python(datetime.datetime.now())

    order = Order(submitDate=today)


    status = OrderItem.ORDER_ITEM_STATUS_CHOICES[0][0]
    order.user = request.user
    isforall = 'isforall' in request.POST and request.POST['isforall']
    if request.user.is_superuser:
        order.status = 'A'
        if isforall:
            status = 'P'
            order.user = None



    order.save()
    #print tableData
    for order_item in tableData:
         #print order_item[2]
         if order_item[3] == '':
             category = None
         else:
             category = Category.objects.filter(pk=order_item[3])[0]

         orderitem=OrderItem(order=order,
                               category=category,
                               quantity=int(order_item[1]),
                               description = order_item[4],
                               status= status  #if it's admin and the order belongs to the public ..., if it's admin the order is accepted
         )
         orderitem.save()
         if request.user.is_superuser and isforall:
             inform_purchase_agent(subject='سفارش نیازمند خرید است',message=render_to_string('mail/buy_orderitem.html',{'orderitem' : orderitem}))

    c = {'rlink' : '../../myorders/' , 'success' : "سفارش شما با موفقیت ثبت شد تا لحظاتی دیگر به فهرست سفارشاتتان خواهید رفت"}

    if request.user.is_superuser:
        if not isforall :
            inform_warehouse_manager( message=render_to_string('mail/order_warehouse_manager.html', {'order': order}),
                                      subject='سفارش نیازمند بررسی است')

    else:
        inform_admin('سفارش جدید', render_to_string('mail/order_added.html', {'order': order}))
    return render_to_response("success.html",c);