Create pdv.
This commit is contained in:
parent
482f5dcc9a
commit
8186dd1a59
@ -1,18 +1,18 @@
|
||||
items:
|
||||
- name: "Pão Parmesão"
|
||||
cod: 1003
|
||||
code: 1003
|
||||
description: "Pão feito de parmesão"
|
||||
price_wpp: 18
|
||||
price_ifood: 20
|
||||
is_a_combo: false
|
||||
- name: "Pão Integral"
|
||||
cod: 1002
|
||||
code: 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
|
||||
code: 1032
|
||||
description: "2 Paes"
|
||||
price_wpp: 19
|
||||
price_ifood: 21
|
||||
|
@ -31,13 +31,13 @@ def add_item():
|
||||
else:
|
||||
Order.add_item(options[chosen_item])
|
||||
|
||||
os.system('clear')
|
||||
print(chr(27) + "[2J")
|
||||
add_item()
|
||||
|
||||
|
||||
def print_summary():
|
||||
print('Summary:')
|
||||
summary = Order.get_string()
|
||||
summary = Order.get_summary_string()
|
||||
clipboard.copy(summary)
|
||||
print(summary)
|
||||
|
||||
@ -46,6 +46,13 @@ def 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():
|
||||
Order.remove_latest_item()
|
||||
|
||||
@ -56,14 +63,14 @@ def clear_all_items():
|
||||
|
||||
main_menu_options = {
|
||||
'1': {'func': add_item, 'name': 'Add item'},
|
||||
'2': {'func': print_summary, 'name': 'Copy Summary/PDV to Clipboard'},
|
||||
'3': {'func': parse_ifood_string, 'name': 'Parse Ifood into PDVS'},
|
||||
'4': {'func': remove_latest_item, 'name': 'Remove Last item'},
|
||||
'5': {'func': clear_all_items, 'name': 'Clear Order'},
|
||||
'6': {'func': return_func, 'name': 'Exit'},
|
||||
'2': {'func': print_summary, 'name': 'Copy Summary to Clipboard'},
|
||||
'3': {'func': print_pdv, 'name': 'Copy PDV to Clipboard'},
|
||||
'4': {'func': parse_ifood_string, 'name': 'Parse Ifood into PDVS'},
|
||||
'5': {'func': remove_latest_item, 'name': 'Remove Last item'},
|
||||
'6': {'func': clear_all_items, 'name': 'Clear Order'},
|
||||
'7': {'func': return_func, 'name': 'Exit'},
|
||||
}
|
||||
|
||||
|
||||
def print_main_menu_options():
|
||||
print("Choose an Option:")
|
||||
for k, c in main_menu_options.items():
|
||||
|
34
src/order.py
34
src/order.py
@ -1,4 +1,13 @@
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
import itertools
|
||||
|
||||
|
||||
class Menu:
|
||||
name = 'name'
|
||||
code = 'code'
|
||||
description = 'description'
|
||||
price_wpp = 'price_wpp'
|
||||
|
||||
|
||||
class OrderItem:
|
||||
@ -29,7 +38,8 @@ class Order:
|
||||
|
||||
@staticmethod
|
||||
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']
|
||||
|
||||
@staticmethod
|
||||
@ -47,23 +57,33 @@ class Order:
|
||||
item += 1
|
||||
|
||||
@staticmethod
|
||||
def get_string():
|
||||
def get_menu_as_dict():
|
||||
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
|
||||
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']}"""
|
||||
f"""**{item.number}x - {menu_as_dict[item.name][Menu.name]}**\n"""
|
||||
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 = '\n'.join(output)
|
||||
output += f'\n**Total Price**: R${price}'
|
||||
|
||||
output += f'\n**Preço Total**: R${price}'
|
||||
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
|
||||
def remove_latest_item():
|
||||
Order.items = Order.items[:-1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user