Browse Source

Create pdv.

main
gabriel becker 2 years ago
parent
commit
8186dd1a59
  1. 6
      data/menu.yml
  2. 23
      src/__main__.py
  3. 34
      src/order.py
  4. 2
      todo.md

6
data/menu.yml

@ -1,18 +1,18 @@
items: items:
- name: "Pão Parmesão" - name: "Pão Parmesão"
cod: 1003 code: 1003
description: "Pão feito de parmesão" description: "Pão feito de parmesão"
price_wpp: 18 price_wpp: 18
price_ifood: 20 price_ifood: 20
is_a_combo: false is_a_combo: false
- name: "Pão Integral" - name: "Pão Integral"
cod: 1002 code: 1002
description: "Pão feito de de farinha integral" description: "Pão feito de de farinha integral"
price_wpp: 19 price_wpp: 19
price_ifood: 21 price_ifood: 21
is_a_combo: false is_a_combo: false
- name: "2 Pães 15% off" - name: "2 Pães 15% off"
cod: 1032 code: 1032
description: "2 Paes" description: "2 Paes"
price_wpp: 19 price_wpp: 19
price_ifood: 21 price_ifood: 21

23
src/__main__.py

@ -31,13 +31,13 @@ def add_item():
else: else:
Order.add_item(options[chosen_item]) Order.add_item(options[chosen_item])
os.system('clear') print(chr(27) + "[2J")
add_item() add_item()
def print_summary(): def print_summary():
print('Summary:') print('Summary:')
summary = Order.get_string() summary = Order.get_summary_string()
clipboard.copy(summary) clipboard.copy(summary)
print(summary) print(summary)
@ -46,6 +46,13 @@ def parse_ifood_string():
print('parse_ifood_string') print('parse_ifood_string')
def print_pdv():
pdvs = Order.get_order_pdv()
str_pdvs = ','.join(map(str, pdvs))
clipboard.copy(str_pdvs)
print(str_pdvs)
def remove_latest_item(): def remove_latest_item():
Order.remove_latest_item() Order.remove_latest_item()
@ -56,14 +63,14 @@ def clear_all_items():
main_menu_options = { main_menu_options = {
'1': {'func': add_item, 'name': 'Add item'}, '1': {'func': add_item, 'name': 'Add item'},
'2': {'func': print_summary, 'name': 'Copy Summary/PDV to Clipboard'}, '2': {'func': print_summary, 'name': 'Copy Summary to Clipboard'},
'3': {'func': parse_ifood_string, 'name': 'Parse Ifood into PDVS'}, '3': {'func': print_pdv, 'name': 'Copy PDV to Clipboard'},
'4': {'func': remove_latest_item, 'name': 'Remove Last item'}, '4': {'func': parse_ifood_string, 'name': 'Parse Ifood into PDVS'},
'5': {'func': clear_all_items, 'name': 'Clear Order'}, '5': {'func': remove_latest_item, 'name': 'Remove Last item'},
'6': {'func': return_func, 'name': 'Exit'}, '6': {'func': clear_all_items, 'name': 'Clear Order'},
'7': {'func': return_func, 'name': 'Exit'},
} }
def print_main_menu_options(): def print_main_menu_options():
print("Choose an Option:") print("Choose an Option:")
for k, c in main_menu_options.items(): for k, c in main_menu_options.items():

34
src/order.py

@ -1,4 +1,13 @@
import yaml import yaml
from pathlib import Path
import itertools
class Menu:
name = 'name'
code = 'code'
description = 'description'
price_wpp = 'price_wpp'
class OrderItem: class OrderItem:
@ -29,7 +38,8 @@ class Order:
@staticmethod @staticmethod
def load_menu(): def load_menu():
with open("../data/menu.yml", "r") as stream: path = Path(__file__).parents[1].resolve()/'data'/'menu.yml'
with open(path, "r") as stream:
Order.menu = yaml.safe_load(stream)['items'] Order.menu = yaml.safe_load(stream)['items']
@staticmethod @staticmethod
@ -47,23 +57,33 @@ class Order:
item += 1 item += 1
@staticmethod @staticmethod
def get_string(): def get_menu_as_dict():
menu_as_dict = {x['name']: x for x in Order.menu} menu_as_dict = {x['name']: x for x in Order.menu}
return menu_as_dict
@staticmethod
def get_summary_string():
menu_as_dict = Order.get_menu_as_dict()
price = 0 price = 0
output = [] output = []
for item in Order.items: for item in Order.items:
item_str = ( item_str = (
f"""**{item.number}x - {menu_as_dict[item.name]['name']}**\n""" f"""**{item.number}x - {menu_as_dict[item.name][Menu.name]}**\n"""
f"""{menu_as_dict[item.name]['description']}""" f"""{menu_as_dict[item.name][Menu.description]}"""
) )
price += item.number * menu_as_dict[item.name]['price_wpp'] price += item.number * menu_as_dict[item.name][Menu.price_wpp]
output.append(item_str) output.append(item_str)
output = '\n'.join(output) output = '\n'.join(output)
output += f'\n**Total Price**: R${price}' output += f'\n**Preço Total**: R${price}'
return output return output
@staticmethod
def get_order_pdv():
menu_dict = Order.get_menu_as_dict()
pdvs = [item.number * [menu_dict[item.name][Menu.code]] for item in Order.items]
pdvs = list(itertools.chain(*pdvs))
return pdvs
@staticmethod @staticmethod
def remove_latest_item(): def remove_latest_item():
Order.items = Order.items[:-1] Order.items = Order.items[:-1]

2
todo.md

@ -1,6 +1,6 @@
- [ ] PDV creation - [x] PDV creation
- [ ] parsing ifood string - [ ] parsing ifood string
- [ ] create setup.py - [ ] create setup.py
- [ ] add cli option to add menu file as a parameter with a default location - [ ] add cli option to add menu file as a parameter with a default location

Loading…
Cancel
Save