def calculate_price(self): total_price = self._price for ingredient_type in self._ingredients.values(): for ingredient in ingredient_type.values(): if not isNaN(ingredient.amount) and not isNaN( ingredient.additional_price): total_price += ingredient.additional_price * ingredient.amount self._total_price = total_price
def check_order_availability(self, inventory: Inventory) -> bool: temp_inventory = deepcopy(inventory) for items_list in self.items.values(): for item in items_list: for ingredient_list in item._ingredients.values(): if ingredient_list.__class__.__name__ == "Ingredient": if not temp_inventory.is_available( ingredient_list.name, ingredient_list.amount): print( f"Inventory not enough for {ingredient_list.amount} {ingredient_list.name}" ) return False temp_inventory.update_stock(ingredient_list.name, -ingredient_list.amount) else: for ingredient in ingredient_list.values(): assert ( ingredient.__class__.__name__ == "Ingredient") if not isNaN(ingredient.amount ) and not temp_inventory.is_available( ingredient.name, ingredient.amount): print( f"Inventory not enough for {ingredient.amount} {ingredient.name}" ) return False temp_inventory.update_stock( ingredient.name, -ingredient.amount) return True
def __str__(self): Wraps = [ f"{wrap.name}: {wrap.amount}" for wrap in self._ingredients['Wrap'].values() if not isNaN(wrap.amount) and wrap.amount >= 0 ] Patties = [ f"{patty.name}: {patty.amount}" for patty in self._ingredients['Patty'].values() if not isNaN(patty.amount) and patty.amount >= 0 ] Others = [ f"{other.name}: {other.amount}" for other in self._ingredients['Other'].values() if not isNaN(other.amount) and other.amount >= 0 ] return ( f"{self._type}: {self._name} \nIngredients: \n\t- Wraps: {Wraps} \n\t- Patties: {Patties} \n\t- Others: {Others} \nNet Price: ${self.price:.2f} \nDescription: {self._description}" )
def ingredients(self): Wraps = [ f"{wrap.name}: {wrap.amount}" for wrap in self._ingredients['Wrap'].values() if not isNaN(wrap.amount) and wrap.amount >= 0 ] Patties = [ f"{patty.name}: {patty.amount}" for patty in self._ingredients['Patty'].values() if not isNaN(patty.amount) and patty.amount >= 0 ] Others = [ f"{other.name}: {other.amount}" for other in self._ingredients['Other'].values() if not isNaN(other.amount) and other.amount >= 0 ] return ( f"Ingredients: \n\t- Wraps: {Wraps} \n\t- Patties: {Patties} \n\t- Others: {Others}" )
def __str__(self): Buns = [ f"{bun.name}: {bun.amount}" for bun in self._ingredients['Bun'].values() if not isNaN(bun.amount) and bun.amount > 0 ] Patties = [ f"{patty.name}: {patty.amount}" for patty in self._ingredients['Patty'].values() if not isNaN(patty.amount) and patty.amount > 0 ] Others = [ f"{other.name}: {other.amount}" for other in self._ingredients['Other'].values() if not isNaN(other.amount) and other.amount > 0 ] return ( f"{self._type}: {self._name} \nIngredients: \n\t- Buns: {Buns} \n\t- Patties: {Patties} \n\t- Others: {Others} \nNet Price: ${self.price:.2f} \nDescription: {self._description}" )
def ingredients(self): Buns = [ f"{bun.name}: {bun.amount}" for bun in self._ingredients['Bun'].values() if not isNaN(bun.amount) and bun.amount > 0 ] Patties = [ f"{patty.name}: {patty.amount}" for patty in self._ingredients['Patty'].values() if not isNaN(patty.amount) and patty.amount > 0 ] Others = [ f"{other.name}: {other.amount}" for other in self._ingredients['Other'].values() if not isNaN(other.amount) and other.amount > 0 ] return ( f"Ingredients: \n\t- Buns: {Buns} \n\t- Patties: {Patties} \n\t- Others: {Others}" )
def _check_availability(self, inventory: Inventory): for ingredient in self._ingredients.values(): if ingredient.amount == 0: self._is_available = False return else: if (not isNaN(ingredient.amount) and not inventory.is_available(ingredient.name, ingredient.amount)): self._is_available = False return self._is_available = True
def update_order_inventory(self, inventory: Inventory): for items_list in self.items.values(): for item in items_list: for ingredient_list in item._ingredients.values(): if ingredient_list.__class__.__name__ == "Ingredient": inventory.update_stock(ingredient_list.name, -ingredient_list.amount) else: for ingredient in ingredient_list.values(): assert ( ingredient.__class__.__name__ == "Ingredient") if not isNaN(ingredient.amount): inventory.update_stock(ingredient.name, -ingredient.amount)
def getSumInMain(self, ingredient_type: str): sum = 0 for ingredient in self._ingredients[ingredient_type].values(): sum += ingredient.amount if not isNaN(ingredient.amount) else 0 return sum