commit 848f71c9d7507e9736e863876ba8f405affbdb2f Author: João Pedro Neiva Date: Wed Aug 24 19:03:39 2022 -0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7275bb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv/ diff --git a/data/menu.yml b/data/menu.yml new file mode 100644 index 0000000..a9ac95f --- /dev/null +++ b/data/menu.yml @@ -0,0 +1,20 @@ +items: + - name: "Pão Parmesão" + cod: 1003 + description: "Pão feito de parmesão" + price_wpp: 18 + price_ifood: 20 + is_a_combo: false + - name: "Pão Integral" + cod: 1002 + description: "Pão feito de de farinha integral" + price_wpp: 19 + price_ifood: 21 + is_a_combo: false + - name: "2 Pães 15% off" + cod: 1032 + description: "2 Paes" + price_wpp: 19 + price_ifood: 21 + is_a_combo: true + sub-items: [1003, 1002] diff --git a/registro-agil.sh b/registro-agil.sh new file mode 100755 index 0000000..0429fc1 --- /dev/null +++ b/registro-agil.sh @@ -0,0 +1,2 @@ +#!/bin/zsh +/Users/joaopedroneiva/PycharmProjects/registro-agil-pedidos/venv/bin/python /Users/joaopedroneiva/PycharmProjects/registro-agil-pedidos/src/__main__.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f9e25c5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pyyaml +ipython \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e69de29 diff --git a/src/__main__.py b/src/__main__.py new file mode 100644 index 0000000..8be7bcd --- /dev/null +++ b/src/__main__.py @@ -0,0 +1,85 @@ +import os +from src.order import Order + + +main_menu_options = """ +Choose an option: +1 - Add item +2 - Print Summary/PDV +3 - Parse Ifood into PDVS +4 - Remove Last item +5 - Clear Order +6 - Exit +""" + + +def add_item(): + print('Add item') + options = Order.list_options() + for i, x in enumerate(options): + print(f'{i+1} - {x}') + print('x - return to main menu') + print_summary() + print('\n:') + chosen_item = input() + + if chosen_item == 'x': + return + try: + chosen_item = int(chosen_item) - 1 + except ValueError: + print(f'Invalid option {chosen_item}') + if not chosen_item < len(options): + print('Invalid Item') + else: + Order.add_item(options[chosen_item]) + + os.system('clear') + add_item() + + +def print_summary(): + print('Summary:') + print(Order.get_string()) + + +def parse_ifood_string(): + print('parse_ifood_string') + + +def remove_latest_item(): + Order.remove_latest_item() + + +def clear_all_items(): + Order.clear_all_items() + + +def menu(): + while True: + print(main_menu_options) + chosen_option = input() + + os.system('clear') + + if chosen_option == '1': + add_item() + elif chosen_option == '2': + print_summary() + elif chosen_option == '3': + parse_ifood_string() + elif chosen_option == '4': + remove_latest_item() + elif chosen_option == '5': + clear_all_items() + elif chosen_option == '6': + return + else: + print('Choose a valid option.') + + +if __name__ == '__main__': + os.system('clear') + + Order.load_menu() + menu() diff --git a/src/__pycache__/order.cpython-37.pyc b/src/__pycache__/order.cpython-37.pyc new file mode 100644 index 0000000..08ae1fc Binary files /dev/null and b/src/__pycache__/order.cpython-37.pyc differ diff --git a/src/order.py b/src/order.py new file mode 100644 index 0000000..c110aa0 --- /dev/null +++ b/src/order.py @@ -0,0 +1,39 @@ +import yaml + + +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): + Order.items.append(item_name) + + @staticmethod + def get_string(): + menu_as_dict = {x['name']: x for x in Order.menu} + __items = list(map(lambda x: menu_as_dict[x], Order.items)) + + output = [f"**{x['name']}**\n{x['description']}" for x in __items] + + output = '\n'.join(output) + + return output + + @staticmethod + def remove_latest_item(): + Order.items = Order.items[:-1] + + + @staticmethod + def clear_all_items(): + Order.items = list() diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..b441e64 --- /dev/null +++ b/test.txt @@ -0,0 +1,11 @@ +Item Qtde Valor unit. Incentivo Subtotal +Pão Parmesão artesanal 450g 15 fatias congeladas Pao Paes Pães 1 R$ 26,99 R$ 0,00 R$ 26,99 +Pão Multigrãos semi-integral artesanal 450g 15 fatias congeladas Pao Paes Pães 1 R$ 26,99 R$ 0,00 R$ 26,99 +Pão fermentação natural + manteiga grátis saborizada alecrim 20g 1 R$ 22,99 R$ 0,00 R$ 26,99 +Pão Multigrãos semi-integral artesanal 450g 15 fatias congeladas Pao Paes Pães 1 R$ 4,00 R$ 4,00 +Manteiga saborizada com alecrim 20g 1 R$ 0,00 R$ 0,00 +3 itens | Subtotal: R$ 80,97 +Taxa de entrega: +Tempo de entrega: 33 minutos +R$ 12,99 +Total do pedido R$ 93,96