示例#1
0
def localPullInventory(request):
    store = request.GET['shopid']
    requests_sent = RequestDetails.objects.filter(store_id=store)
    for r in requests_sent:
        inv = Inventory.objects.filter(product_id_id=r.product_id,store_id_id=store)        
        batchid = random.randint(1,99999)
        ids = []
        for i in inv:
            ids.append(i.batch_id)
        while(batchid in ids):
                batchid = random.randint(1,99999)
        batches = Inventory.objects.filter(product_id_id = r.product_id, store_id_id = store).order_by('-batch_id')
        newbatch = Inventory(product_id_id=r.product_id,store_id_id=store,batch_id=batchid,qty = r.qty,selling_price = batches[0].selling_price, cost_price=batches[0].cost_price, minimum_qty = batches[0].minimum_qty, expiry_date=batches[0].expiry_date)
        newbatch.save()
        r.delete()
    inventory = Inventory.objects.filter(store_id_id=store)     
    if(inventory is not None):
        list = []
        for i in inventory:
            list.append({'qty' : str(i.qty), 
                         'batchid' : str(i.batch_id),
                         'productid': str(i.product_id_id),
                         'minimum_qty': str(i.minimum_qty),
                         'selling_price' : str(i.selling_price),
                         'cost_price' : str(i.cost_price),
                         'minimum_qty': str(i.minimum_qty),
                         'expiry_date': str(i.expiry_date)}) 
	
	payload = { 'inventory': list }
    data = json.dumps(payload)
    return HttpResponse(data, content_type="application/json")					 
示例#2
0
def localPullInventory(request):
    store = request.GET['shopid']
    requests_sent = RequestDetails.objects.filter(store_id=store)
    for r in requests_sent:
        inv = Inventory.objects.filter(product_id_id=r.product_id,
                                       store_id_id=store)
        batchid = random.randint(1, 99999)
        ids = []
        for i in inv:
            ids.append(i.batch_id)
        while (batchid in ids):
            batchid = random.randint(1, 99999)
        batches = Inventory.objects.filter(
            product_id_id=r.product_id,
            store_id_id=store).order_by('-batch_id')
        newbatch = Inventory(product_id_id=r.product_id,
                             store_id_id=store,
                             batch_id=batchid,
                             qty=r.qty,
                             selling_price=batches[0].selling_price,
                             cost_price=batches[0].cost_price,
                             minimum_qty=batches[0].minimum_qty,
                             expiry_date=batches[0].expiry_date)
        newbatch.save()
        r.delete()
    inventory = Inventory.objects.filter(store_id_id=store)
    if (inventory is not None):
        list = []
        for i in inventory:
            list.append({
                'qty': str(i.qty),
                'batchid': str(i.batch_id),
                'productid': str(i.product_id_id),
                'minimum_qty': str(i.minimum_qty),
                'selling_price': str(i.selling_price),
                'cost_price': str(i.cost_price),
                'minimum_qty': str(i.minimum_qty),
                'expiry_date': str(i.expiry_date)
            })

        payload = {'inventory': list}
    data = json.dumps(payload)
    return HttpResponse(data, content_type="application/json")
def invenf():			
    inventory = []
    inventoryList = []
    with open("Inventory_100.txt") as f:
        for line in f:
            inventory = re.split(":",line)
            t = []
            for i in range(len(inventory)):
                t.append(inventory[i].strip('\n').split(",")[0])
            inventoryList.append(t)
    counter = 0			
    for word in inventoryList:
        p = Product(name = (word[0]),manufacturer = (word[2]),product_id = int(word[3]),category = word[1],min_restock = 0.1*int(word[5]))
        p.save()
        a = 1
        while (a<=5):
            if(counter%50 == 0):
                			
                inObj1 = Inventory(minimum_qty = int(word[6]), qty = int(word[5]),batch_id = 00001,cost_price = Decimal(word[4]),selling_price = Decimal(str(1.05))*Decimal(word[4]) ,product_id_id = int(word[3]),store_id_id=a,expiry_date=datetime.date(2013,12,15))
                inObj2 = Inventory(minimum_qty = int(word[6]), qty = int(word[5]),batch_id = 00002,cost_price = Decimal(str(1.1))*Decimal(word[4]),selling_price = Decimal(str(1.15))*Decimal(word[4]) ,product_id_id = int(word[3]),store_id_id=a,expiry_date=datetime.date(2013,12,16))
            else:
                inObj1 = Inventory(minimum_qty = int(word[6]), qty = int(word[5]),batch_id = 00001,cost_price = Decimal(word[4]),selling_price = Decimal(str(1.05))*Decimal(word[4]) ,product_id_id = int(word[3]),store_id_id=a)
                inObj2 = Inventory(minimum_qty = int(word[6]), qty = int(word[5]),batch_id = 00002,cost_price = Decimal(str(1.1))*Decimal(word[4]),selling_price = Decimal(str(1.15))*Decimal(word[4]) ,product_id_id = int(word[3]),store_id_id=a)
            inObj1.save()
            inObj2.save()
            a = a + 1
        counter = counter + 1