From fc6d38599b405820b3c266a31ef21a3a0f3f0a73 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Sat, 5 Jul 2025 10:51:52 +0700 Subject: (andri) fix --- indoteknik_custom/models/patch/__init__.py | 1 + .../models/patch/__pycache__/__init__.py | 1 - .../models/patch/__pycache__/http_override.py | 46 ---------------------- indoteknik_custom/models/patch/http_override.py | 45 +++++++++++++++++++++ 4 files changed, 46 insertions(+), 47 deletions(-) create mode 100644 indoteknik_custom/models/patch/__init__.py delete mode 100644 indoteknik_custom/models/patch/__pycache__/__init__.py delete mode 100644 indoteknik_custom/models/patch/__pycache__/http_override.py create mode 100644 indoteknik_custom/models/patch/http_override.py (limited to 'indoteknik_custom') 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/__pycache__/__init__.py b/indoteknik_custom/models/patch/__pycache__/__init__.py deleted file mode 100644 index 051b6537..00000000 --- a/indoteknik_custom/models/patch/__pycache__/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import http_override \ No newline at end of file diff --git a/indoteknik_custom/models/patch/__pycache__/http_override.py b/indoteknik_custom/models/patch/__pycache__/http_override.py deleted file mode 100644 index e1978edb..00000000 --- a/indoteknik_custom/models/patch/__pycache__/http_override.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -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 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 -- cgit v1.2.3