Example #1
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 #2
0
	def getLocationBoxAbove(self, inventoryDetailsId):

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

		inventoryDAO = InventoryDAO(connector)
		reservedInv = inventoryDAO.selectAnEntry(inventoryDetailsId)

		itemsOnStack = inventoryDAO.selectEntries("X_index", reservedInv[2])

		x_encoder = reservedInv[4]
		y_encoder = 0

		#if no box at the top, set to 0
		if len(itemsOnStack)-1 != reservedInv[3]:
			for item in itemsOnStack:
				if item[3] == reservedInv[3]+1:
					y_encoder = item[5]
					break

		return [x_encoder, y_encoder]