From 848f71c9d7507e9736e863876ba8f405affbdb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Neiva?= Date: Wed, 24 Aug 2022 19:03:39 -0300 Subject: [PATCH] Initial commit --- .gitignore | 1 + data/menu.yml | 20 +++++++ registro-agil.sh | 2 + requirements.txt | 2 + setup.py | 0 src/__main__.py | 85 +++++++++++++++++++++++++++ src/__pycache__/order.cpython-37.pyc | Bin 0 -> 2039 bytes src/order.py | 39 ++++++++++++ test.txt | 11 ++++ 9 files changed, 160 insertions(+) create mode 100644 .gitignore create mode 100644 data/menu.yml create mode 100755 registro-agil.sh create mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 src/__main__.py create mode 100644 src/__pycache__/order.cpython-37.pyc create mode 100644 src/order.py create mode 100644 test.txt 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 0000000000000000000000000000000000000000..08ae1fc26ecfba5ad42a4b9c397722ecfa7a4030 GIT binary patch literal 2039 zcma)7&yU+g6rLG7UMF#Omn|*3r~-rvk|Q;##C5eov=W>`p+X=_XqbAYsaJNKj-85) zvZoXQCxno=R7mZSe`&6qdgj&(yf>3L*=>bzG%qinH}k&ty&w6c*Xs~?KKeaK?|X#& zg+JC0{3aj6s@?`6iKID6$fray={+IRTe5^odXL2Z3)m;46y^G9&VC1P6ah<;Fy$>t z;;R*%Pv)NeH?peXF-YZ^^*w9ng1VX!S1WZP~GU1bSCSR`1CkAlNmn&$U## zfk44)8`f=DRUbqR@FiQaU#^{#nm%I-@|;TVh}0hUzlPwxAYYPi;2Xmk&G!d`p%k?k z7HTpZoE5pD+O)D-6;<3aemPYW|8NBs_P9G(4UY3N6?t_6%KAvmEU9`2PHo+cjB32zL}cjV%Y%BRa5Y zyaq~!Y1~Cam&o5%iPRBn+Ax4?B+$_Bx0qh#P-dyi;agy_&fyIg+*s8dN;aE}w=&oq zxIj9FeFbm8%KZrt9bvoCk@HXW0lbFVim!yg+Z6kX zHw*p}b9xuN;OzWAlr=?fXeSOfb#Hv!FMB5S!|W}@M260H0+^+@v6}UIB0C)VA< c!>1dy>@E-=tSw)6g$a)x;1isCHq_Aj7tYYOpa1{> literal 0 HcmV?d00001 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