コード例 #1
0
ファイル: sync.py プロジェクト: CG3002-Design-Project/CG3002
def pull_inventory_from_hq(request):
	print "entered pull from hq"
	payload = {'shopid': shopid }
	r = requests.get(hq_host_inventory_pull,params=payload)
	data = json.loads(r.text)
	invent = data['inventory']
	for i in invent:
		product_id = int(i['productid'])
		batch_id = int(i['batchid'])
		qty = int(i['qty'])
		cost_price = Decimal(i['cost_price'])
		expiry_date = i['expiry_date']
		selling_price = Decimal(i['selling_price'])
		minimum_qty = int(i['minimum_qty'])
		
		inventor = Inventory.objects.filter(product_id=product_id, batch_id=batch_id) 

		for inventory in inventor:
			if(inventory is not None): 
				inventory.product_id = product_id
				inventory.batch_id = batch_id
				inventory.qty = qty
				inventory.cost_price = cost_price
				if(expiry_date != 'None'):
					expiry_date = datetime.datetime.strptime(i['expiry_date'], '%Y-%m-%d').date()
					inventory.expiry_date = expiry_date
				inventory.selling_price = selling_price
				inventory.minimum_qty = minimum_qty
				inventory.save();
			else:
				if(expiry_date != 'None'):
					expiry_date = datetime.datetime.strptime(i['expiry_date'], '%Y-%m-%d').date()
					inventory.expiry_date = expiry_date
				inventory_new = Inventory(product_id_id = product_id,
									  batch_id = batch_id,
									  qty = qty,
									  cost_price = cost_price,
									  expiry_date = expiry_date,
									  selling_price = selling_price,
									  minimum_qty = minimum_qty);
			
				inventory_new.save()
	

	etran = data['etran']
	for t in etran:
		transaction_id = int(t['transaction_id'])
		transaction_date = t['transaction_date']
		product_id = int(t['product_id'])
		batch_id = int(t['batch_id'])
		qty = int(t['quantity_sold'])
		cost_price = Decimal(t['cost_price'])
		selling_price = Decimal(t['selling_price'])
		status = t['status']		
		et = eTransaction(transaction_id=transaction_id,transaction_date=transaction_date,product_id=product_id,batch_id=batch_id,quantity_sold = qty,selling_price=selling_price,cost_price=cost_price,status=status) 
		et.save()
		inv = Inventory.objects.get(product_id_id=product_id,batch_id=batch_id)
		inv.qty = inv.qty - qty
		inv.save()		
	return render(request,'sync_function.html');	
コード例 #2
0
    def handle(self, **options):
        print "entered pull from hq"
        payload = {'shopid': shopid}
        r = requests.get(hq_host_inventory_pull, params=payload)
        data = json.loads(r.text)
        invent = data['inventory']
        for i in invent:
            product_id = int(i['productid'])
            batch_id = int(i['batchid'])
            qty = int(i['qty'])
            cost_price = Decimal(i['cost_price'])
            expiry_date = i['expiry_date']
            selling_price = Decimal(i['selling_price'])
            minimum_qty = int(i['minimum_qty'])

            inventor = Inventory.objects.filter(product_id_id=product_id,
                                                batch_id=batch_id)

            for inventory in inventor:
                if (inventory is not None):
                    inventory.product_id_id = product_id
                    inventory.batch_id = batch_id
                    inventory.qty = qty
                    inventory.cost_price = cost_price
                    if (expiry_date != 'None'):
                        expiry_date = datetime.datetime.strptime(
                            i['expiry_date'], '%Y-%m-%d').date()
                        inventory.expiry_date = expiry_date
                    inventory.selling_price = selling_price
                    inventory.minimum_qty = minimum_qty
                    inventory.save()
                else:
                    if (expiry_date != 'None'):
                        expiry_date = datetime.datetime.strptime(
                            i['expiry_date'], '%Y-%m-%d').date()
                        inventory.expiry_date = expiry_date
                    inventory_new = Inventory(product_id_id=product_id,
                                              batch_id=batch_id,
                                              qty=qty,
                                              cost_price=cost_price,
                                              expiry_date=expiry_date,
                                              selling_price=selling_price,
                                              minimum_qty=minimum_qty)

                    inventory_new.save()
        return HttpResponse('inventory pull')
        #return render(request,'sync_function.html');


# To set this up:
# 1. Create file pricing_strategy_cronjob
# 2. In the file, add below line
# 0 0 * * 0-6 python manage.py recalculate_price
# (min hr day month day_run Command) << File format, this job runs recalculate_price.py every day at 12am
# 3. On Unix system, run this to set it up: crontab -a pricing_strategy_cronjob
コード例 #3
0
    def handle(self, **options):
		print "entered pull from hq"
		payload = {'shopid': shopid }
		r = requests.get(hq_host_inventory_pull,params=payload)
		data = json.loads(r.text)
		invent = data['inventory']
		for i in invent:
			product_id = int(i['productid'])
			batch_id = int(i['batchid'])
			qty = int(i['qty'])
			cost_price = Decimal(i['cost_price'])
			expiry_date = i['expiry_date']
			selling_price = Decimal(i['selling_price'])
			minimum_qty = int(i['minimum_qty'])
			
			inventor = Inventory.objects.filter(product_id_id=product_id, batch_id=batch_id) 

			for inventory in inventor:
				if(inventory is not None): 
					inventory.product_id_id = product_id
					inventory.batch_id = batch_id
					inventory.qty = qty
					inventory.cost_price = cost_price
					if(expiry_date != 'None'):
						expiry_date = datetime.datetime.strptime(i['expiry_date'], '%Y-%m-%d').date()
						inventory.expiry_date = expiry_date
					inventory.selling_price = selling_price
					inventory.minimum_qty = minimum_qty
					inventory.save();
				else:
					if(expiry_date != 'None'):
						expiry_date = datetime.datetime.strptime(i['expiry_date'], '%Y-%m-%d').date()
						inventory.expiry_date = expiry_date
					inventory_new = Inventory(product_id_id = product_id,
										  batch_id = batch_id,
										  qty = qty,
										  cost_price = cost_price,
										  expiry_date = expiry_date,
										  selling_price = selling_price,
										  minimum_qty = minimum_qty);
				
					inventory_new.save()
		return HttpResponse('inventory pull')
		#return render(request,'sync_function.html');

# To set this up:
# 1. Create file pricing_strategy_cronjob
# 2. In the file, add below line 
# 0 0 * * 0-6 python manage.py recalculate_price 
# (min hr day month day_run Command) << File format, this job runs recalculate_price.py every day at 12am
# 3. On Unix system, run this to set it up: crontab -a pricing_strategy_cronjob                 
コード例 #4
0
def inventoryf():			
	inventory = []
	inventoryList = []
	with open("test.txt") as f:
		for line in f:
			inventory = re.split(":",line)
			t = []
			for i in range(8):
				t.append(inventory[i].strip('\n').split(",")[0])
			inventoryList.append(t)
		
	for word in inventoryList:
		inObj = Inventory(minimum_qty = int(word[6]),name = word[0], qty = int(word[5]), manufacturer = word[2], batch_id = 00000000,cost_price = float(word[4]),selling_price = 0000000, product_id = int(word[3]), category = word[1]) 
		inObj.save()
コード例 #5
0
def inventoryf():
    inventory = []
    inventoryList = []
    with open("test.txt") as f:
        for line in f:
            inventory = re.split(":", line)
            t = []
            for i in range(8):
                t.append(inventory[i].strip('\n').split(",")[0])
            inventoryList.append(t)

    for word in inventoryList:
        inObj = Inventory(minimum_qty=int(word[6]),
                          name=word[0],
                          qty=int(word[5]),
                          manufacturer=word[2],
                          batch_id=00000000,
                          cost_price=float(word[4]),
                          selling_price=0000000,
                          product_id=int(word[3]),
                          category=word[1])
        inObj.save()
コード例 #6
0
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]),min_restock = 0.1*int(word[5]),category = word[1],status = 'false')
        p.save()

        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(1.05)*Decimal(word[4]) ,product_id_id = int(word[3]),expiry_date=datetime.date(2013,12,15),strategy_percentage=0)
			inObj2 = Inventory(minimum_qty = int(word[6]), qty = int(word[5]),batch_id = 00002,cost_price = Decimal(1.1)*Decimal(word[4]),selling_price = Decimal(1.15)*Decimal(word[4]) ,product_id_id = int(word[3]),expiry_date=datetime.date(2013,12,16),strategy_percentage=0)
        else:
			inObj1 = Inventory(minimum_qty = int(word[6]), qty = int(word[5]),batch_id = 00001,cost_price = Decimal(word[4]),selling_price = Decimal(1.05)*Decimal(word[4]) ,product_id_id = int(word[3]),strategy_percentage=0)
			inObj2 = Inventory(minimum_qty = int(word[6]), qty = int(word[5]),batch_id = 00002,cost_price = Decimal(1.1)*Decimal(word[4]),selling_price = Decimal(1.15)*Decimal(word[4]) ,product_id_id = int(word[3]),strategy_percentage=0)
        inObj1.save()
        inObj2.save()
        counter = counter + 1
コード例 #7
0
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]),
                    min_restock=0.1 * int(word[5]),
                    category=word[1],
                    status='false')
        p.save()

        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(1.05) * Decimal(word[4]),
                               product_id_id=int(word[3]),
                               expiry_date=datetime.date(2013, 12, 15),
                               strategy_percentage=0)
            inObj2 = Inventory(minimum_qty=int(word[6]),
                               qty=int(word[5]),
                               batch_id=00002,
                               cost_price=Decimal(1.1) * Decimal(word[4]),
                               selling_price=Decimal(1.15) * Decimal(word[4]),
                               product_id_id=int(word[3]),
                               expiry_date=datetime.date(2013, 12, 16),
                               strategy_percentage=0)
        else:
            inObj1 = Inventory(minimum_qty=int(word[6]),
                               qty=int(word[5]),
                               batch_id=00001,
                               cost_price=Decimal(word[4]),
                               selling_price=Decimal(1.05) * Decimal(word[4]),
                               product_id_id=int(word[3]),
                               strategy_percentage=0)
            inObj2 = Inventory(minimum_qty=int(word[6]),
                               qty=int(word[5]),
                               batch_id=00002,
                               cost_price=Decimal(1.1) * Decimal(word[4]),
                               selling_price=Decimal(1.15) * Decimal(word[4]),
                               product_id_id=int(word[3]),
                               strategy_percentage=0)
        inObj1.save()
        inObj2.save()
        counter = counter + 1
コード例 #8
0
def pull_inventory_from_hq(request):
    print "entered pull from hq"
    payload = {'shopid': shopid}
    r = requests.get(hq_host_inventory_pull, params=payload)
    data = json.loads(r.text)
    invent = data['inventory']
    for i in invent:
        product_id = int(i['productid'])
        batch_id = int(i['batchid'])
        qty = int(i['qty'])
        cost_price = Decimal(i['cost_price'])
        expiry_date = i['expiry_date']
        selling_price = Decimal(i['selling_price'])
        minimum_qty = int(i['minimum_qty'])

        inventor = Inventory.objects.filter(product_id=product_id,
                                            batch_id=batch_id)

        for inventory in inventor:
            if (inventory is not None):
                inventory.product_id = product_id
                inventory.batch_id = batch_id
                inventory.qty = qty
                inventory.cost_price = cost_price
                if (expiry_date != 'None'):
                    expiry_date = datetime.datetime.strptime(
                        i['expiry_date'], '%Y-%m-%d').date()
                    inventory.expiry_date = expiry_date
                inventory.selling_price = selling_price
                inventory.minimum_qty = minimum_qty
                inventory.save()
            else:
                if (expiry_date != 'None'):
                    expiry_date = datetime.datetime.strptime(
                        i['expiry_date'], '%Y-%m-%d').date()
                    inventory.expiry_date = expiry_date
                inventory_new = Inventory(product_id_id=product_id,
                                          batch_id=batch_id,
                                          qty=qty,
                                          cost_price=cost_price,
                                          expiry_date=expiry_date,
                                          selling_price=selling_price,
                                          minimum_qty=minimum_qty)

                inventory_new.save()

    etran = data['etran']
    for t in etran:
        transaction_id = int(t['transaction_id'])
        transaction_date = t['transaction_date']
        product_id = int(t['product_id'])
        batch_id = int(t['batch_id'])
        qty = int(t['quantity_sold'])
        cost_price = Decimal(t['cost_price'])
        selling_price = Decimal(t['selling_price'])
        status = t['status']
        et = eTransaction(transaction_id=transaction_id,
                          transaction_date=transaction_date,
                          product_id=product_id,
                          batch_id=batch_id,
                          quantity_sold=qty,
                          selling_price=selling_price,
                          cost_price=cost_price,
                          status=status)
        et.save()
        inv = Inventory.objects.get(product_id_id=product_id,
                                    batch_id=batch_id)
        inv.qty = inv.qty - qty
        inv.save()
    return render(request, 'sync_function.html')