Skip to content
Snippets Groups Projects
Commit d1a821c3 authored by lejeune quentin's avatar lejeune quentin
Browse files

[IMP] hw_posbox_upgrade: Integrate the hw_posbox_upgrade module in hw_posbox homepage

We move the main.py controller and the upgrade.html view
in the hw_posbox_homepage module for more consistency

X-original-commit: 9ba84dc6
parent 93257bd2
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ from odoo import http
import os
from odoo.tools import misc
from pathlib import Path
import threading
from uuid import getnode as get_mac
from odoo.addons.hw_proxy.controllers import main as hw_proxy
......@@ -46,8 +47,12 @@ 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')
list_credential_template = jinja_env.get_template('list_credential.html')
upgrade_page_template = jinja_env.get_template('upgrade_page.html')
class IoTboxHomepage(web.Home):
def __init__(self):
super(IoTboxHomepage,self).__init__()
self.upgrading = threading.Lock()
def get_six_terminal(self):
terminal_id = helpers.read_file_first_line('odoo-six-payment-terminal.conf')
......@@ -280,3 +285,20 @@ class IoTboxHomepage(web.Home):
helpers.unlink_file('odoo-six-payment-terminal.conf')
subprocess.check_call(["sudo", "service", "odoo", "restart"])
return "<meta http-equiv='refresh' content='0; url=http://" + helpers.get_ip() + ":8069'>"
@http.route('/hw_proxy/upgrade', type='http', auth='none', )
def upgrade(self):
commit = subprocess.check_output(["git", "--work-tree=/home/pi/odoo/", "--git-dir=/home/pi/odoo/.git", "log", "-1"]).decode('utf-8').replace("\n", "<br/>")
return upgrade_page_template.render({
'title': "Odoo's IoTBox - Software Upgrade",
'breadcrumb': 'IoT Box Software Upgrade',
'loading_message': 'Updating IoT box',
'commit': commit,
})
@http.route('/hw_proxy/perform_upgrade', type='http', auth='none')
def perform_upgrade(self):
self.upgrading.acquire()
os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/posbox_update.sh')
self.upgrading.release()
return 'SUCCESS'
{% extends "layout.html" %}
{% macro loading_block_ui(message) %}
<div class="loading-block o_hide">
<div class="loading-message-block">
<div style="height: 50px">
<img src="/web/static/src/img/spin.png" style="animation: spin 4s infinite linear;" alt="Loading...">
</div>
<br>
<div class="loading-message">
<span class="message-title">Please wait..</span><br>
<span class="message-status">{{ message }}</span>
</div>
</div>
</div>
{% endmacro %}
{% from "loading.html" import loading_block_ui %}
{% block head %}
<script type="text/javascript" src="/web/static/lib/jquery/jquery.js"></script>
<script>
$(function(){
$(function() {
var upgrading = false;
$('#upgrade').click(function(){
if(!upgrading){
$('#upgrade').click(function() {
if (!upgrading) {
upgrading = true;
$('.loading-block').removeClass('o_hide');
$.ajax({
url:'/hw_proxy/perform_upgrade/'
}).done(function(status){
}).done(function() {
$('.message-title').text('Upgrade successful');
var cpt = 110;
setInterval(function(){
setInterval(function() {
--cpt;
if(cpt==0){location.reload();}
if (cpt === 0) {location.reload();}
$('.message-status').text('Restarting the IoTBox. Available in ' + cpt);
} , 1000);
}).fail(function(){
}).fail(function() {
$('.error-message').text('Upgrade Failed');
});
}
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'IoTBox Software Upgrader',
'category': 'Sales/Point Of Sale',
'website': 'https://www.odoo.com/page/point-of-sale-hardware',
'sequence': 6,
'summary': 'Remotely upgrade the IoTBox software',
'description': """
IoTBox Software Upgrader
========================
This module allows to remotely upgrade the IoTBox software to a
new version. This module is specific to the IoTBox setup and environment
and should not be installed on regular Odoo servers.
""",
'depends': ['hw_proxy'],
'installable': False,
}
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import main
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import os
import jinja2
import json
import subprocess
import sys
import threading
from odoo import http
from odoo.addons.hw_proxy.controllers import main as hw_proxy
_logger = logging.getLogger(__name__)
if hasattr(sys, 'frozen'):
# When running on compiled windows binary, we don't have access to package loader.
path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'views'))
loader = jinja2.FileSystemLoader(path)
else:
loader = jinja2.PackageLoader('odoo.addons.hw_posbox_upgrade', "views")
jinja_env = jinja2.Environment(loader=loader, autoescape=True)
jinja_env.filters["json"] = json.dumps
upgrade_page_template = jinja_env.get_template('upgrade_page.html')
class PosboxUpgrader(hw_proxy.Proxy):
def __init__(self):
super(PosboxUpgrader,self).__init__()
self.upgrading = threading.Lock()
@http.route('/hw_proxy/upgrade', type='http', auth='none', )
def upgrade(self):
commit = subprocess.check_output(["git", "--work-tree=/home/pi/odoo/", "--git-dir=/home/pi/odoo/.git", "log", "-1"]).decode('utf-8').replace("\n", "<br/>")
return upgrade_page_template.render({
'title': "Odoo's IoTBox - Software Upgrade",
'breadcrumb': 'IoT Box Software Upgrade',
'loading_message': 'Updating IoT box',
'commit': commit,
})
@http.route('/hw_proxy/perform_upgrade', type='http', auth='none')
def perform_upgrade(self):
self.upgrading.acquire()
os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/posbox_update.sh')
self.upgrading.release()
return 'SUCCESS'
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<title>{{ title or "Odoo's IoTBox" }}</title>
<style>
body {
width: 600px;
margin: 30px auto;
font-family: sans-serif;
text-align: justify;
color: #6B6B6B;
background-color: #f1f1f1;
}
.text-green {
color: #28a745;
}
.text-red {
color: #dc3545;
}
.text-blue {
color: #007bff;
}
.text-center {
text-align: center;
}
.float-right {
float: right;
}
.btn {
display: inline-block;
padding: 8px 15px;
border: 1px solid #dadada;
border-radius: 3px;
font-weight: bold;
font-size: 0.8rem;
background: #fff;
color: #00a09d;
cursor: pointer;
}
.btn-sm {
padding: 4px 8px;
font-size: 0.7rem;
font-weight: normal;
}
.btn:hover {
background-color: #f1f1f1;
}
a {
text-decoration: none;
color: #00a09d;
}
a:hover {
color: #006d6b;
}
.container {
padding: 10px 20px;
background: #ffffff;
border-radius: 8px;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.17);
}
.breadcrumb {
margin-bottom: 10px;
font-size: 0.9rem;
}
input[type="text"], input[type="password"] {
padding: 6px 12px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 3px;
color: inherit;
}
select {
padding: 6px 12px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 3px;
color: inherit;
background: #ffffff;
width: 100%;
}
.o_hide {
display: none;
}
.font-small {
font-size: 0.8rem;
}
.footer {
margin-top: 12px;
text-align: right;
}
.footer a {
margin-left: 8px;
}
.loading-block {
position: absolute;
background-color: #0a060661;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 9999;
}
.loading-message-block {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.loading-message {
font-size: 14px;
line-height: 20px;
color:white
}
@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
</style>
{% block head %}{% endblock %}
</head>
<body>
{%if breadcrumb %}
<div class="breadcrumb"><a href="/">Home</a> / <span>{{ breadcrumb }}</span></div>
{% endif %}
<div class="container">
{% block content %}{% endblock %}
<p class="error-message text-red" style="text-align: right;" />
</div>
<div class="footer">
<a href='https://www.odoo.com/help'>Help</a>
<a href='https://www.odoo.com/documentation/user/13.0/iot.html'>Documentation</a>
</div>
</body>
</html>
......@@ -26,7 +26,7 @@ test -x $DAEMON || exit 0
set -e
function _start() {
start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $DAEMON -- --config $CONFIG --logfile $LOGFILE --load=web,hw_proxy,hw_posbox_homepage,hw_posbox_upgrade,hw_escpos,hw_blackbox_be,hw_drivers
start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $DAEMON -- --config $CONFIG --logfile $LOGFILE --load=web,hw_proxy,hw_posbox_homepage,hw_escpos,hw_blackbox_be,hw_drivers
}
function _stop() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment