summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAntoine Prieels <anp@odoo.com>2020-10-13 12:55:09 +0000
committerAntoine Prieels <anp@odoo.com>2020-10-19 13:42:10 +0000
commita6012f03ff02f04a3d128e33326f932fd22f0ced (patch)
tree4c10dc1e6042e4862dfca91e537fdc2bf26145cc /addons
parentaa287dc0f2316277d1e509b0c9033431a76d6590 (diff)
[IMP] hw_drivers: Remove http.py.iotpatch
We used to patch http.py using a diff. This was really not practical because every time the file was modified, the diff had to be recreated. We now override the specific methods directly. closes odoo/odoo#59855 Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/hw_drivers/__init__.py1
-rw-r--r--addons/hw_drivers/http.py34
-rw-r--r--addons/point_of_sale/tools/posbox/overwrite_after_init/home/pi/odoo/odoo/http.py.iotpatch20
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