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)
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]
def getDepositLocation(self): dbConnect = DbConnect(InventoryDAO.getDbDir()) connector = dbConnect.getConnection() inventoryDAO = InventoryDAO(connector) c_maxXIndex = InventoryInfo.sc_maxXIndex c_maxYIndex = InventoryInfo.sc_maxYIndex oneStackEntries = list() x_idx = 0 for x_idx in range(0, c_maxXIndex): oneStackEntries = inventoryDAO.selectEntries("X_index", x_idx) if(len(oneStackEntries) <= c_maxYIndex): break newXIdx = x_idx newYIdx = len(oneStackEntries) x_encoder = ArduinoService.sc_xEncodingValues[newXIdx] y_encoder = 6700 # the way stocking works for column 0 is different from column 1 and 2 if newXIdx != 0 and newYIdx == 2: return [newxIdx, newYIdx, x_encoder, 36000] # !TODO: CHANGE THIS maxBoxSize = InventoryInfo.sc_maxBoxSize maxY_encoder = 6700 if newYIdx > 0: for item in oneStackEntries: if maxY_encoder < item[5]: maxY_encoder = item[5] y_encoder = maxY_encoder + maxBoxSize return [newXIdx, newYIdx, x_encoder, y_encoder]