Compare commits
2 Commits
848f71c9d7
...
482f5dcc9a
Author | SHA1 | Date | |
---|---|---|---|
|
482f5dcc9a | ||
|
38d806ae8c |
@ -1,2 +1,3 @@
|
||||
pyyaml
|
||||
ipython
|
||||
ipython
|
||||
clipboard
|
||||
|
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
@ -1,16 +1,11 @@
|
||||
import os
|
||||
import clipboard
|
||||
|
||||
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 return_func():
|
||||
return False
|
||||
|
||||
|
||||
def add_item():
|
||||
@ -29,6 +24,8 @@ def add_item():
|
||||
chosen_item = int(chosen_item) - 1
|
||||
except ValueError:
|
||||
print(f'Invalid option {chosen_item}')
|
||||
add_item()
|
||||
return
|
||||
if not chosen_item < len(options):
|
||||
print('Invalid Item')
|
||||
else:
|
||||
@ -40,7 +37,9 @@ def add_item():
|
||||
|
||||
def print_summary():
|
||||
print('Summary:')
|
||||
print(Order.get_string())
|
||||
summary = Order.get_string()
|
||||
clipboard.copy(summary)
|
||||
print(summary)
|
||||
|
||||
|
||||
def parse_ifood_string():
|
||||
@ -55,31 +54,42 @@ def 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():
|
||||
while True:
|
||||
print(main_menu_options)
|
||||
should_not_exit = True
|
||||
while should_not_exit:
|
||||
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:
|
||||
chosen_option = main_menu_options.get(chosen_option)
|
||||
if chosen_option is None:
|
||||
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__':
|
||||
os.system('clear')
|
||||
|
||||
if os.getenv('TERM') is None:
|
||||
os.environ['TERM'] = 'xterm'
|
||||
Order.load_menu()
|
||||
menu()
|
||||
|
44
src/order.py
44
src/order.py
@ -1,6 +1,28 @@
|
||||
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:
|
||||
items = list()
|
||||
menu = dict()
|
||||
@ -16,16 +38,29 @@ class Order:
|
||||
|
||||
@staticmethod
|
||||
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
|
||||
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]
|
||||
|
||||
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 += f'\n**Total Price**: R${price}'
|
||||
|
||||
return output
|
||||
|
||||
@ -33,7 +68,6 @@ class Order:
|
||||
def remove_latest_item():
|
||||
Order.items = Order.items[:-1]
|
||||
|
||||
|
||||
@staticmethod
|
||||
def clear_all_items():
|
||||
Order.items = list()
|
||||
|
Loading…
x
Reference in New Issue
Block a user