def addFromStock(name, price, takeAmount): global items global stockItems global updateItemStock global addItem for item in stock_items: # if the name matches our search if (item.getName() == name): newStockAmount = (item.getAmount() - takeAmount) item.setAmount(newStockAmount) continue else: continue raise exceptions.ItemNotExists( "Item {} doesn't exist in stock".format(name)) for thing in items: # if the name matches our search if (thing.getName() == name): totalAmount = thing.getAmount() + takeAmount thing.setPrice(price) thing.setAmount(totalAmount) else: product = Product(name, price, takeAmount) if product in items: print("Error: Item {} already exists".format(name)) else: items.append(product) break for item in stock_items: if item.getAmount() <= 0: deleteStockItem(item.getName())
def deleteItem(name): global items isDeleted = False for item in items: # if the name is the same as we search if (item.getName() == name): items.remove(item) isDeleted = True else: continue if (isDeleted != True): raise exceptions.ItemNotExists("Not found {} item.".format(name))
def updateItem(name, price, amount): global items isUpdated = False # control all items step by step for item in items: # if the name is the same as we search if (item.getName() == name): # update item item.setPrice(price) item.setAmount(amount) isUpdated = True else: continue if (isUpdated != True): raise exceptions.ItemNotExists("Not found {} item".format(name))