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');
def handle(self, **options): print "entered pull from hq" payload = {'shopid': shopid } r = requests.get(hq_host_e_pull,params=payload) data = json.loads(r.text) 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()
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')