Create clipboard and price processing.
This commit is contained in:
parent
38d806ae8c
commit
482f5dcc9a
@ -1,3 +1,3 @@
|
|||||||
pyyaml
|
pyyaml
|
||||||
ipython
|
ipython
|
||||||
pyperclip
|
clipboard
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
|
import clipboard
|
||||||
|
|
||||||
from src.order import Order
|
from src.order import Order
|
||||||
|
|
||||||
|
|
||||||
main_menu_options = """
|
def return_func():
|
||||||
Choose an option:
|
return False
|
||||||
1 - Add item
|
|
||||||
2 - Print Summary/PDV
|
|
||||||
3 - Parse Ifood into PDVS
|
|
||||||
4 - Remove Last item
|
|
||||||
5 - Clear Order
|
|
||||||
6 - Exit
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def add_item():
|
def add_item():
|
||||||
@ -42,7 +37,9 @@ def add_item():
|
|||||||
|
|
||||||
def print_summary():
|
def print_summary():
|
||||||
print('Summary:')
|
print('Summary:')
|
||||||
print(Order.get_string())
|
summary = Order.get_string()
|
||||||
|
clipboard.copy(summary)
|
||||||
|
print(summary)
|
||||||
|
|
||||||
|
|
||||||
def parse_ifood_string():
|
def parse_ifood_string():
|
||||||
@ -57,27 +54,37 @@ def clear_all_items():
|
|||||||
Order.clear_all_items()
|
Order.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'},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def print_main_menu_options():
|
||||||
|
print("Choose an Option:")
|
||||||
|
for k, c in main_menu_options.items():
|
||||||
|
print(f"{k} - {c['name']}")
|
||||||
|
|
||||||
|
|
||||||
def menu():
|
def menu():
|
||||||
while True:
|
should_not_exit = True
|
||||||
print(main_menu_options)
|
while should_not_exit:
|
||||||
|
print_main_menu_options()
|
||||||
chosen_option = input()
|
chosen_option = input()
|
||||||
|
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
|
|
||||||
if chosen_option == '1':
|
chosen_option = main_menu_options.get(chosen_option)
|
||||||
add_item()
|
if chosen_option is None:
|
||||||
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.')
|
print('Choose a valid option.')
|
||||||
|
else:
|
||||||
|
option_callable = chosen_option['func']
|
||||||
|
should_not_exit = option_callable()
|
||||||
|
should_not_exit = True if should_not_exit is None else should_not_exit
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
44
src/order.py
44
src/order.py
@ -1,6 +1,28 @@
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
class OrderItem:
|
||||||
|
def __init__(self, name, code=None):
|
||||||
|
self.name = name
|
||||||
|
self.code = code
|
||||||
|
self.number = 0
|
||||||
|
|
||||||
|
def set_quantity(self, number):
|
||||||
|
self.number = number
|
||||||
|
|
||||||
|
def add_item(self):
|
||||||
|
self.number += 1
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.name == other.name
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<OrderItem {self.name} x{self.number}>'
|
||||||
|
|
||||||
|
def __add__(self, other):
|
||||||
|
self.number += other
|
||||||
|
|
||||||
|
|
||||||
class Order:
|
class Order:
|
||||||
items = list()
|
items = list()
|
||||||
menu = dict()
|
menu = dict()
|
||||||
@ -16,16 +38,29 @@ class Order:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_item(item_name):
|
def add_item(item_name):
|
||||||
Order.items.append(item_name)
|
item = OrderItem(item_name)
|
||||||
|
if item in Order.items:
|
||||||
|
previous_item = Order.items[Order.items.index(item)]
|
||||||
|
previous_item += 1
|
||||||
|
else:
|
||||||
|
Order.items.append(item)
|
||||||
|
item += 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_string():
|
def get_string():
|
||||||
menu_as_dict = {x['name']: x for x in Order.menu}
|
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]
|
|
||||||
|
|
||||||
|
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']}"""
|
||||||
|
)
|
||||||
|
price += item.number * menu_as_dict[item.name]['price_wpp']
|
||||||
|
output.append(item_str)
|
||||||
output = '\n'.join(output)
|
output = '\n'.join(output)
|
||||||
|
output += f'\n**Total Price**: R${price}'
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@ -33,7 +68,6 @@ class Order:
|
|||||||
def remove_latest_item():
|
def remove_latest_item():
|
||||||
Order.items = Order.items[:-1]
|
Order.items = Order.items[:-1]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clear_all_items():
|
def clear_all_items():
|
||||||
Order.items = list()
|
Order.items = list()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user