import yaml class OrderItem: def __init__(self, name, code=None): self.name = name self.code = code self.number = 0 def set_quantity(self, number): self.number = number def add_item(self): self.number += 1 def __eq__(self, other): return self.name == other.name def __repr__(self): return f'' def __add__(self, other): self.number += other class Order: items = list() menu = dict() @staticmethod def load_menu(): with open("../data/menu.yml", "r") as stream: Order.menu = yaml.safe_load(stream)['items'] @staticmethod def list_options(): return [option['name']for option in Order.menu] @staticmethod def add_item(item_name): item = OrderItem(item_name) if item in Order.items: previous_item = Order.items[Order.items.index(item)] previous_item += 1 else: Order.items.append(item) item += 1 @staticmethod def get_string(): menu_as_dict = {x['name']: x for x in Order.menu} price = 0 output = [] for item in Order.items: item_str = ( f"""**{item.number}x - {menu_as_dict[item.name]['name']}**\n""" f"""{menu_as_dict[item.name]['description']}""" ) price += item.number * menu_as_dict[item.name]['price_wpp'] output.append(item_str) output = '\n'.join(output) output += f'\n**Total Price**: R${price}' return output @staticmethod def remove_latest_item(): Order.items = Order.items[:-1] @staticmethod def clear_all_items(): Order.items = list()