From cc063512bdf820db7e14ca242a1a98fd6edd4964 Mon Sep 17 00:00:00 2001 From: Antoine Prieels Date: Thu, 23 May 2019 09:33:17 +0200 Subject: [PATCH] [IMP] hw_posbox_homepage: Six payment terminal Add configuration for a Six payment terminal on the IoTBox's homepage. The Terminal ID specified on the homepage is saved to: `/home/pi/odoo-six-payment-terminal.conf` TaskId: 1932416 --- addons/hw_posbox_homepage/controllers/main.py | 35 +++++++++++ addons/hw_posbox_homepage/views/homepage.html | 7 +++ .../views/six_payment_terminal.html | 61 +++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 addons/hw_posbox_homepage/views/six_payment_terminal.html diff --git a/addons/hw_posbox_homepage/controllers/main.py b/addons/hw_posbox_homepage/controllers/main.py index 36a22356327..6494d11bc4f 100644 --- a/addons/hw_posbox_homepage/controllers/main.py +++ b/addons/hw_posbox_homepage/controllers/main.py @@ -53,6 +53,7 @@ wifi_config_template = jinja_env.get_template('wifi_config.html') driver_list_template = jinja_env.get_template('driver_list.html') remote_connect_template = jinja_env.get_template('remote_connect.html') configure_wizard_template = jinja_env.get_template('configure_wizard.html') +six_payment_terminal_template = jinja_env.get_template('six_payment_terminal.html') class IoTboxHomepage(web.Home): @@ -72,6 +73,12 @@ class IoTboxHomepage(web.Home): statuses[driver] = hw_proxy.drivers[driver].get_status() return statuses + def get_six_terminal(self): + path = Path.home() / 'odoo-six-payment-terminal.conf' + if path.exists(): + return path.read_text() + return 'Not Configured' + def get_homepage_data(self): hostname = str(socket.gethostname()) mac = get_mac() @@ -113,6 +120,7 @@ class IoTboxHomepage(web.Home): 'mac': ":".join(i + next(h) for i in h), 'iot_device_status': iot_device, 'server_status': get_odoo_server_url() or 'Not Configured', + 'six_terminal': self.get_six_terminal(), 'network_status': network, } @@ -296,3 +304,30 @@ class IoTboxHomepage(web.Home): return 'starting with ' + auth_token else: return 'already running' + + @http.route('/six_payment_terminal', type='http', auth='none', cors='*', csrf=False) + def six_payment_terminal(self): + return six_payment_terminal_template.render({ + 'title': 'Six Payment Terminal', + 'breadcrumb': 'Six Payment Terminal', + 'terminalId': self.get_six_terminal(), + }) + + @http.route('/six_payment_terminal_add', type='http', auth='none', cors='*', csrf=False) + def add_six_payment_terminal(self, terminal_id): + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) + path = Path.home() / 'odoo-six-payment-terminal.conf' + path.write_text(terminal_id) + subprocess.check_call(["sudo", "service", "odoo", "restart"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + return 'http://' + get_ip() + ':8069' + + @http.route('/six_payment_terminal_clear', type='http', auth='none', cors='*', csrf=False) + def clear_six_payment_terminal(self): + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) + path = Path.home() / 'odoo-six-payment-terminal.conf' + if path.exists(): + path.unlink() + subprocess.check_call(["sudo", "service", "odoo", "restart"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + return "" diff --git a/addons/hw_posbox_homepage/views/homepage.html b/addons/hw_posbox_homepage/views/homepage.html index 74a502f7ca7..d70238fc54f 100644 --- a/addons/hw_posbox_homepage/views/homepage.html +++ b/addons/hw_posbox_homepage/views/homepage.html @@ -22,6 +22,7 @@ font-weight: bold; vertical-align: top; width: 30%; + text-align: left; } .device-status { margin: 6px 0; @@ -109,6 +110,12 @@ Server {{ server_status }}configure + {% if server_status != "Not Configured" %} + + Six payment terminal + {{ six_terminal }} configure + + {% endif %} IOT Device diff --git a/addons/hw_posbox_homepage/views/six_payment_terminal.html b/addons/hw_posbox_homepage/views/six_payment_terminal.html new file mode 100644 index 00000000000..622c6a84a6e --- /dev/null +++ b/addons/hw_posbox_homepage/views/six_payment_terminal.html @@ -0,0 +1,61 @@ +{% extends "layout.html" %} +{% from "loading.html" import loading_block_ui %} +{% block head %} + +{% endblock %} +{% block content %} +

Six Payment Terminal

+

+ Set the Terminal ID (TID) of the terminal you want to use. +

+
+ + + + + + + + +
Terminal ID
+
+ {{ loading_block_ui(loading_message) }} +
+ {% if terminalId %} +

+ Current Terminal Id: {{ terminalId }} +

+
+ You can clear the terminal configuration +
+ +
+
+ {% endif %} +{% endblock %}