Compare commits
No commits in common. "482f5dcc9a5f819e80efc07c5df38698c479d406" and "848f71c9d7507e9736e863876ba8f405affbdb2f" have entirely different histories.
482f5dcc9a
...
848f71c9d7
@ -1,3 +1,2 @@
|
|||||||
pyyaml
|
pyyaml
|
||||||
ipython
|
ipython
|
||||||
clipboard
|
|
@ -1,11 +1,16 @@
|
|||||||
import os
|
import os
|
||||||
import clipboard
|
|
||||||
|
|
||||||
from src.order import Order
|
from src.order import Order
|
||||||
|
|
||||||
|
|
||||||
def return_func():
|
main_menu_options = """
|
||||||
return False
|
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():
|
def add_item():
|
||||||
@ -24,8 +29,6 @@ def add_item():
|
|||||||
chosen_item = int(chosen_item) - 1
|
chosen_item = int(chosen_item) - 1
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(f'Invalid option {chosen_item}')
|
print(f'Invalid option {chosen_item}')
|
||||||
add_item()
|
|
||||||
return
|
|
||||||
if not chosen_item < len(options):
|
if not chosen_item < len(options):
|
||||||
print('Invalid Item')
|
print('Invalid Item')
|
||||||
else:
|
else:
|
||||||
@ -37,9 +40,7 @@ def add_item():
|
|||||||
|
|
||||||
def print_summary():
|
def print_summary():
|
||||||
print('Summary:')
|
print('Summary:')
|
||||||
summary = Order.get_string()
|
print(Order.get_string())
|
||||||
clipboard.copy(summary)
|
|
||||||
print(summary)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_ifood_string():
|
def parse_ifood_string():
|
||||||
@ -54,42 +55,31 @@ 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():
|
||||||
should_not_exit = True
|
while True:
|
||||||
while should_not_exit:
|
print(main_menu_options)
|
||||||
print_main_menu_options()
|
|
||||||
chosen_option = input()
|
chosen_option = input()
|
||||||
|
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
|
|
||||||
chosen_option = main_menu_options.get(chosen_option)
|
if chosen_option == '1':
|
||||||
if chosen_option is None:
|
add_item()
|
||||||
print('Choose a valid option.')
|
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:
|
else:
|
||||||
option_callable = chosen_option['func']
|
print('Choose a valid option.')
|
||||||
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__':
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
if os.getenv('TERM') is None:
|
|
||||||
os.environ['TERM'] = 'xterm'
|
|
||||||
Order.load_menu()
|
Order.load_menu()
|
||||||
menu()
|
menu()
|
||||||
|
44
src/order.py
44
src/order.py
@ -1,28 +1,6 @@
|
|||||||
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()
|
||||||
@ -38,29 +16,16 @@ class Order:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_item(item_name):
|
def add_item(item_name):
|
||||||
item = OrderItem(item_name)
|
Order.items.append(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
|
||||||
|
|
||||||
@ -68,6 +33,7 @@ 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