[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
This commit is contained in:
Antoine Prieels
2019-08-12 08:16:04 +02:00
parent 8becb17b8a
commit cc063512bd
3 changed files with 103 additions and 0 deletions
@@ -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 "<meta http-equiv='refresh' content='0; url=http://" + get_ip() + ":8069'>"
@@ -22,6 +22,7 @@
font-weight: bold;
vertical-align: top;
width: 30%;
text-align: left;
}
.device-status {
margin: 6px 0;
@@ -109,6 +110,12 @@
<td class="heading">Server</td>
<td><a href='{{ server_status }}' target=_blank>{{ server_status }}<a class="btn btn-sm float-right" href='/server'>configure</a></td>
</tr>
{% if server_status != "Not Configured" %}
<tr>
<td class="heading">Six payment terminal</td>
<td>{{ six_terminal }} <a class="btn btn-sm float-right" href='/six_payment_terminal'>configure</a></td>
</tr>
{% endif %}
<tr>
<td class="heading">IOT Device</td>
<td>
@@ -0,0 +1,61 @@
{% extends "layout.html" %}
{% from "loading.html" import loading_block_ui %}
{% block head %}
<script>
var _onQueryDone = function () {
$('.message-status').html('Updated configuration <br> Refreshing page');
setTimeout(function () {
location.reload();
}, 30000);
}
$(document).ready(function () {
$('#terminal-id').submit(function(e){
e.preventDefault();
$('.loading-block').removeClass('o_hide');
$.ajax({
url: '/six_payment_terminal_add',
type: 'post',
data: $('#terminal-id').serialize(),
}).always(_onQueryDone);
});
$('#terminal-clear').submit(function(e){
e.preventDefault();
$('.loading-block').removeClass('o_hide');
$.ajax({
url: '/six_payment_terminal_clear',
type: 'get',
}).always(_onQueryDone);
});
});
</script>
{% endblock %}
{% block content %}
<h2 class="text-center">Six Payment Terminal</h2>
<p>
Set the Terminal ID (TID) of the terminal you want to use.
</p>
<form id="terminal-id" action='/six_payment_terminal_add' method='POST'>
<table align="center">
<tr>
<td>Terminal ID</td>
<td><input type="text" name="terminal_id"></td>
</tr>
<tr>
<td/>
<td><input class="btn" type="submit" value="Connect"/></td>
</tr>
</table>
{{ loading_block_ui(loading_message) }}
</form>
{% if terminalId %}
<p class="text-center font-small">
Current Terminal Id: <strong>{{ terminalId }}</strong>
</p>
<div class="text-center font-small" style="margin: 10px auto;">
You can clear the terminal configuration
<form id="terminal-clear" style="display: inline-block;margin-left: 4px;">
<input class="btn btn-sm" type="submit" value="Clear"/>
</form>
</div>
{% endif %}
{% endblock %}