Browse Source

Initial commit

main
João Pedro Neiva 2 years ago committed by joaopedroneiva
commit
848f71c9d7
  1. 1
      .gitignore
  2. 20
      data/menu.yml
  3. 2
      registro-agil.sh
  4. 2
      requirements.txt
  5. 0
      setup.py
  6. 85
      src/__main__.py
  7. BIN
      src/__pycache__/order.cpython-37.pyc
  8. 39
      src/order.py
  9. 11
      test.txt

1
.gitignore vendored

@ -0,0 +1 @@
venv/

20
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]

2
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

2
requirements.txt

@ -0,0 +1,2 @@
pyyaml
ipython

85
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()

BIN
src/__pycache__/order.cpython-37.pyc

Binary file not shown.

39
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()

11
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
Loading…
Cancel
Save