From 8186dd1a59e48f3bb3bc03da7839102b795128a3 Mon Sep 17 00:00:00 2001 From: gabriel becker Date: Tue, 30 Aug 2022 11:20:13 -0300 Subject: [PATCH] Create pdv. --- data/menu.yml | 6 +++--- src/__main__.py | 23 +++++++++++++++-------- src/order.py | 34 +++++++++++++++++++++++++++------- todo.md | 2 +- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/data/menu.yml b/data/menu.yml index a9ac95f..1c2cadc 100644 --- a/data/menu.yml +++ b/data/menu.yml @@ -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 diff --git a/src/__main__.py b/src/__main__.py index 6689cbe..e66f01b 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -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(): diff --git a/src/order.py b/src/order.py index 2d002a8..f57840b 100644 --- a/src/order.py +++ b/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] diff --git a/todo.md b/todo.md index 4fbae30..b055926 100644 --- a/todo.md +++ b/todo.md @@ -1,6 +1,6 @@ - - [ ] PDV creation + - [x] PDV creation - [ ] parsing ifood string - [ ] create setup.py - [ ] add cli option to add menu file as a parameter with a default location