def testProcessRetrievedInventory():
	print(sys._getframe().f_code.co_name + ": ")

	dbConnect = DbConnect(InventoryDAO.getDbDir())
	connector = dbConnect.getConnection()

	customerId = 1
	barcode = 1
	quantity = 2

	androidService = AndroidService()
	inventoryReservation = androidService.reserveInventoryIfAvailable(customerId, barcode, quantity)
	print(inventoryReservation) # (True, reservedInventoryLoc, newVirtualCartRowId)


	arduinoService = ArduinoService()
	print( arduinoService.processRetrievedInventory(1, 1) )

	inventoryDAO = InventoryDAO(connector)
	print( inventoryDAO.selectAllEntries() )

	virtualCartDAO = VirtualCartDAO(connector)
	print( virtualCartDAO.selectAllEntries() )

	print("===================================================")
	print("Testing testProcessRetrievedInventory-------------------complete\n\n\n")
def populateVirtualCart():

	print(sys._getframe().f_code.co_name + ": ")

	dao = VirtualCartDAO(gc_connector)

	# dao.createAnEntry( (1, 1, 1, 0) )
	# dao.createAnEntry( (1, 2, 2, 0) )
	# dao.createAnEntry( (1, 3, 1, 0) )
	# dao.createAnEntry( (2, 1, 1, 0) )
	# dao.createAnEntry( (2, 2, 1, 0) )
	# dao.createAnEntry( (2, 3, 1, 0) )

	print(dao.selectAllEntries())

	print("===================================================")
	print("Testing populateVirtualCart-------------------complete\n\n\n")
Example #3
0
	def reserveInventoryIfAvailable(self, customerId, barcode, quantity):

		dbConnect = DbConnect(BarcodeDAO.getDbDir())
		connector = dbConnect.getConnection()

		# the customer should order the exact amount. For example if there exists 1 item in the
		# back room and the customer ordered 2 items, then the whole transaction is rejected.
		# if returning false, the available quantity
		numAvailableItem = self.__numItemsAvailable(connector, barcode)
		if numAvailableItem < quantity:
			return (False, numAvailableItem)


		barcodeDAO = BarcodeDAO(connector)
		barcodePriKey = barcodeDAO.getPriKeys("Barcode", barcode)[0]


		inventoryDAO = InventoryDAO(connector)
		inventoryEntries = inventoryDAO.selectEntries("BarcodeDetailsFk", barcodePriKey)


		virtualCartDAO = VirtualCartDAO(connector)
		newVirtualCartRowId = virtualCartDAO.createAnEntry( (customerId, barcodePriKey, quantity, 0) )


		reservedInventoryLoc = list()

		reserveCount = 0
		for inventoryEntry in inventoryEntries:

			if reserveCount == quantity:
				break

			if inventoryEntry[6] != 0:
				continue

			inventoryDAO.update(inventoryEntry[0], "CheckoutFlag", 1)

			# [inventoryDetailsId, barcodeDetailsFk, X_index, Y_index, X_encoder, Y_encoder, checkoutFlag]
			entry = inventoryDAO.selectAnEntry(inventoryEntry[0])

			reservedInventoryLoc.append(entry[0:1]+entry[2:6]) # omit barcodeDetailsFk and checkoutFlag
			reserveCount += 1

		return (True, reservedInventoryLoc, newVirtualCartRowId)
Example #4
0
	def processRetrievedInventory(self, inventoryInfoRowId, virtualCartRowId):

		dbConnect = DbConnect(InventoryDAO.getDbDir())
		connector = dbConnect.getConnection()

		# TODO: after debugging this code is done, there should be a check ensuring that there exists
		# such ids

		inventoryDAO = InventoryDAO(connector)
		yIdxColHeader = "Y_index"

		retrievedItemYIndex = inventoryDAO.selectAColumn(yIdxColHeader, inventoryInfoRowId)

		# if the retrieved box is at the top, no need to do updates on y_encoders and y_index
		if retrievedItemYIndex != inventoryDAO.selectMax(yIdxColHeader):
			idBoxAbove = inventoryDAO.getPriKeys(yIdxColHeader, retrievedItemYIndex+1)[0]

			yEncoderColHeader = "Y_encoder"
			encoderOffset = (inventoryDAO.selectAColumn(yEncoderColHeader, idBoxAbove) - 
							 inventoryDAO.selectAColumn(yEncoderColHeader, inventoryInfoRowId))
			
			# update the y_encoder and y_index values for the boxes above the retrieved box
			xIdxColHeader = "X_index"
			retrievedItemXIdx = inventoryDAO.selectAColumn(xIdxColHeader, inventoryInfoRowId)
			sameStackItemIds = inventoryDAO.getPriKeys(xIdxColHeader, retrievedItemXIdx)
			for sameStackItemId in sameStackItemIds:
				curYIdx = inventoryDAO.selectAColumn(yIdxColHeader, sameStackItemId)

				if curYIdx > retrievedItemYIndex:
					inventoryDAO.update(sameStackItemId, yIdxColHeader, curYIdx-1)

					curYEncoder = inventoryDAO.selectAColumn(yEncoderColHeader, sameStackItemId)
					inventoryDAO.update(sameStackItemId, yEncoderColHeader, curYEncoder-encoderOffset)

		inventoryDAO.delete(inventoryInfoRowId)
		print("inventory deleted!!!")


		virtualCartDAO = VirtualCartDAO(connector)

		numItemsForPickup = virtualCartDAO.selectAColumn("NumItemAvailableForPickup", virtualCartRowId)
		virtualCartDAO.update(virtualCartRowId, "NumItemAvailableForPickup", numItemsForPickup+1)