summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/patch
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
commitd15ce4e186e2b77f01e8dfd03886298cc733d4c1 (patch)
tree1b32a4c29c4fcea85070fcecb5b77a7d55d30029 /indoteknik_custom/models/patch
parentdeba962d7368a5c4e30441b5a640102608e3dde6 (diff)
parent36a53535dbdc5777266fd9276b4c557259dab6be (diff)
<hafid> merging odoo-backup
Diffstat (limited to 'indoteknik_custom/models/patch')
-rw-r--r--indoteknik_custom/models/patch/__init__.py1
-rw-r--r--indoteknik_custom/models/patch/http_override.py45
2 files changed, 46 insertions, 0 deletions
diff --git a/indoteknik_custom/models/patch/__init__.py b/indoteknik_custom/models/patch/__init__.py
new file mode 100644
index 00000000..051b6537
--- /dev/null
+++ b/indoteknik_custom/models/patch/__init__.py
@@ -0,0 +1 @@
+from . import http_override \ No newline at end of file
diff --git a/indoteknik_custom/models/patch/http_override.py b/indoteknik_custom/models/patch/http_override.py
new file mode 100644
index 00000000..6bec1343
--- /dev/null
+++ b/indoteknik_custom/models/patch/http_override.py
@@ -0,0 +1,45 @@
+import odoo.http
+import json
+import logging
+from werkzeug.exceptions import BadRequest
+import functools
+
+_logger = logging.getLogger(__name__)
+
+class CustomJsonRequest(odoo.http.JsonRequest):
+ def __init__(self, httprequest):
+ super(odoo.http.JsonRequest, self).__init__(httprequest)
+
+ self.params = {}
+ request_data_raw = self.httprequest.get_data().decode(self.httprequest.charset)
+
+ self.jsonrequest = {}
+ if request_data_raw.strip():
+ try:
+ self.jsonrequest = json.loads(request_data_raw)
+ except ValueError:
+ msg = 'Invalid JSON data: %r' % (request_data_raw,)
+ _logger.info('%s: %s (Handled by CustomJsonRequest)', self.httprequest.path, msg)
+ raise BadRequest(msg)
+ else:
+ _logger.info("CustomJsonRequest: Received empty or whitespace-only JSON body. Treating as empty JSON for webhook.")
+
+ self.params = dict(self.jsonrequest.get("params", {}))
+ self.context = self.params.pop('context', dict(self.session.context))
+
+
+_original_get_request = odoo.http.Root.get_request
+
+@functools.wraps(_original_get_request)
+def _get_request_override(self, httprequest):
+ _logger.info("--- DEBUG: !!! _get_request_override IS CALLED !!! ---")
+ _logger.info(f"--- DEBUG: Request Mimetype: {httprequest.mimetype}, Path: {httprequest.path} ---")
+
+ if httprequest.mimetype in ("application/json", "application/json-rpc"):
+ _logger.debug("Odoo HTTP: Using CustomJsonRequest for mimetype: %s", httprequest.mimetype)
+ return CustomJsonRequest(httprequest)
+ else:
+ _logger.debug("Odoo HTTP: Using original get_request for mimetype: %s", httprequest.mimetype)
+ return _original_get_request(self, httprequest)
+
+odoo.http.Root.get_request = _get_request_override \ No newline at end of file