Пример #1
0
def deduct_inventory(request):
    data = json.loads(request.body)
    inventory = data['product']
    todayDate = datetime.datetime.now()
    b = str(todayDate.year) + '-' + str(todayDate.month) + '-' + str(todayDate.day) 
    trans = Transaction.objects.all().order_by('-transaction_id')
    if not trans:
        id = 1
    else:
        t = Transaction.objects.filter(transaction_date = datetime.datetime.strptime(b, '%Y-%m-%d').date()).order_by('-transaction_id')
        if not t:
            id = 1
        else:
            id = t[0].transaction_id + 1	
    for i in inventory:
        batchid = int(i['batchid'])
        productid=int(i['barcode'])
        qty = int(i['qty'])
        cid = int(i['cid'])
        inv = Inventory.objects.get(product_id_id=productid,batch_id=batchid)
        inv.qty = inv.qty - qty
        inv.save()	
        p = Inventory.objects.get(product_id_id=productid,batch_id=batchid)
        tran = Transaction(transaction_id=id,transaction_date=datetime.datetime.strptime(b, '%Y-%m-%d').date(),product_id=productid,batch_id=batchid,selling_price=p.selling_price,cost_price=p.cost_price,cashier_id=int(cid),quantity_sold=qty)
        tran.save()
    return HttpResponse('hi')
Пример #2
0
def addToTables():
    print "inside function"
    transaction = []
    transactionList = []
    storeid = 00000001
    with open("Trans_50_2_9_1762.txt") as f:
        for line in f:
            transaction = re.split(":", line)
            t = []
            for i in range(len(transaction)):
                t.append(transaction[i].strip('\n').split(",")[0])
            transactionList.append(t)
    print transactionList[0]
    counter = 0
    for word in transactionList:
        tdate = datetime.datetime.strptime(word[5], '%d/%m/%Y').date()
        inventory = Inventory.objects.get(product_id_id=int(word[3]),
                                          batch_id=00000001)
        inventory.qty = inventory.qty - int(word[4])
        inventory.save()
        print counter
        counter += 1
        if (tdate == datetime.date(2013, 9, 30)):
            t = Transaction(transaction_id=int(word[0]),
                            batch_id=00000001,
                            quantity_sold=int(word[4]),
                            product_id=int(word[3]),
                            transaction_date=tdate,
                            cashier_id=int(word[1]),
                            selling_price=inventory.selling_price,
                            cost_price=inventory.cost_price)
            t.save()
Пример #3
0
def save_transaction(request):
	d =  json.loads(request.body)
	t = Transaction.objects.all().order_by('-transaction_id');
	if not t:
		transaction_id = 1;
	else:
		transaction_id = t[0].transaction_id+1;

	for i in d:
		print i;
		t = Transaction(transaction_id= transaction_id, transaction_date = time.strftime("%Y-%m-%d"), product_id = i['barcode'], quantity_sold = i['qty'], batch_id = i['batchid'], cachier_id = "01");
		t.save();
	return HttpResponse("Poornima");
Пример #4
0
def save_transaction(request):
    d = json.loads(request.body)
    t = Transaction.objects.all().order_by('-transaction_id')
    if not t:
        transaction_id = 1
    else:
        transaction_id = t[0].transaction_id + 1

    for i in d:
        print i
        t = Transaction(transaction_id=transaction_id,
                        transaction_date=time.strftime("%Y-%m-%d"),
                        product_id=i['barcode'],
                        quantity_sold=i['qty'],
                        batch_id=i['batchid'],
                        cachier_id="01")
        t.save()
    return HttpResponse("Poornima")
Пример #5
0
def deduct_inventory(request):
    data = json.loads(request.body)
    inventory = data['product']
    todayDate = datetime.datetime.now()
    b = str(todayDate.year) + '-' + str(todayDate.month) + '-' + str(
        todayDate.day)
    trans = Transaction.objects.all().order_by('-transaction_id')
    if not trans:
        id = 1
    else:
        t = Transaction.objects.filter(
            transaction_date=datetime.datetime.strptime(
                b, '%Y-%m-%d').date()).order_by('-transaction_id')
        if not t:
            id = 1
        else:
            id = t[0].transaction_id + 1
    for i in inventory:
        batchid = int(i['batchid'])
        productid = int(i['barcode'])
        qty = int(i['qty'])
        cid = int(i['cid'])
        inv = Inventory.objects.get(product_id_id=productid, batch_id=batchid)
        inv.qty = inv.qty - qty
        inv.save()
        p = Inventory.objects.get(product_id_id=productid, batch_id=batchid)
        tran = Transaction(transaction_id=id,
                           transaction_date=datetime.datetime.strptime(
                               b, '%Y-%m-%d').date(),
                           product_id=productid,
                           batch_id=batchid,
                           selling_price=p.selling_price,
                           cost_price=p.cost_price,
                           cashier_id=int(cid),
                           quantity_sold=qty)
        tran.save()
    return HttpResponse('hi')
Пример #6
0
def addToTables():
    print "inside function"
    transaction = []
    transactionList = []
    storeid = 00000001
    with open("Trans_50_2_9_1762.txt") as f:
        for line in f:
            transaction = re.split(":",line)
            t = []
            for i in range(len(transaction)):
                t.append(transaction[i].strip('\n').split(",")[0])
            transactionList.append(t)
    print transactionList[0]
    counter = 0;
    for word in transactionList:
        tdate = datetime.datetime.strptime(word[5], '%d/%m/%Y').date()	
        inventory  = Inventory.objects.get(product_id_id = int(word[3]),batch_id=00000001)
        inventory.qty = inventory.qty - int(word[4])
        inventory.save()
        print counter;
        counter+=1;
        if (tdate == datetime.date(2013,9,30)):
            t = Transaction(transaction_id = int(word[0]), batch_id = 00000001, quantity_sold = int(word[4]),product_id = int(word[3]),transaction_date = tdate,cashier_id=int(word[1]),selling_price = inventory.selling_price, cost_price = inventory.cost_price)
            t.save()