diff options
| -rw-r--r-- | addons/hw_drivers/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hw_drivers/http.py | 34 | ||||
| -rw-r--r-- | addons/point_of_sale/tools/posbox/overwrite_after_init/home/pi/odoo/odoo/http.py.iotpatch | 20 |
3 files changed, 35 insertions, 20 deletions
diff --git a/addons/hw_drivers/__init__.py b/addons/hw_drivers/__init__.py index b36b894717b..da5e919c051 100644 --- a/addons/hw_drivers/__init__.py +++ b/addons/hw_drivers/__init__.py @@ -6,5 +6,6 @@ from . import controllers from . import driver from . import event_manager from . import exception_logger +from . import http from . import interface from . import main diff --git a/addons/hw_drivers/http.py b/addons/hw_drivers/http.py new file mode 100644 index 00000000000..b0ea9bee700 --- /dev/null +++ b/addons/hw_drivers/http.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import http + + +class IoTBoxHttpRequest(http.HttpRequest): + def dispatch(self): + if self._is_cors_preflight(http.request.endpoint): + # Using the PoS in debug mode in v12, the call to '/hw_proxy/handshake' contains the + # 'X-Debug-Mode' header, which was removed from 'Access-Control-Allow-Headers' in v13. + # When the code of http.py is not checked out to v12 (i.e. in Community), the connection + # fails as the header is rejected and none of the devices can be used. + headers = { + 'Access-Control-Max-Age': 60 * 60 * 24, + 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Debug-Mode' + } + return http.Response(status=200, headers=headers) + return super(IoTBoxHttpRequest, self).dispatch() + + +class IoTBoxRoot(http.Root): + def setup_db(self, httprequest): + # No database on the IoT Box + pass + + def get_request(self, httprequest): + # Override HttpRequestwith IoTBoxHttpRequest + if httprequest.mimetype not in ("application/json", "application/json-rpc"): + return IoTBoxHttpRequest(httprequest) + return super(IoTBoxRoot, self).get_request(httprequest) + +http.Root = IoTBoxRoot +http.root = IoTBoxRoot() diff --git a/addons/point_of_sale/tools/posbox/overwrite_after_init/home/pi/odoo/odoo/http.py.iotpatch b/addons/point_of_sale/tools/posbox/overwrite_after_init/home/pi/odoo/odoo/http.py.iotpatch deleted file mode 100644 index af29b3b9e4d..00000000000 --- a/addons/point_of_sale/tools/posbox/overwrite_after_init/home/pi/odoo/odoo/http.py.iotpatch +++ /dev/null @@ -1,20 +0,0 @@ ---- http_old.py 2020-10-07 15:25:08.432430021 +0200 -+++ http_new.py 2020-10-07 15:26:05.088492713 +0200 -@@ -764,7 +764,7 @@ - if self._is_cors_preflight(request.endpoint): - headers = { - 'Access-Control-Max-Age': 60 * 60 * 24, -- 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization' -+ 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Debug-Mode' - } - return Response(status=200, headers=headers) - -@@ -1510,7 +1510,7 @@ - """ - httprequest = httprequest or request.httprequest - -- dbs = db_list(True, httprequest) -+ dbs = [] - - # try the db already in the session - db_session = httprequest.session.db |
