summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-07-05 10:51:52 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-07-05 10:51:52 +0700
commitfc6d38599b405820b3c266a31ef21a3a0f3f0a73 (patch)
tree97cbc4bb913f76651ae9cc774b7a9f716bae8167
parentd9ddc88ea00a5c86c7cf82552970ab0c917d8544 (diff)
(andri) fix
-rw-r--r--indoteknik_api/controllers/api_v1/stock_picking.py60
-rw-r--r--indoteknik_custom/models/patch/__init__.py (renamed from indoteknik_custom/models/patch/__pycache__/__init__.py)0
-rw-r--r--indoteknik_custom/models/patch/http_override.py (renamed from indoteknik_custom/models/patch/__pycache__/http_override.py)1
3 files changed, 36 insertions, 25 deletions
diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py
index c5a4f7ed..1b247c8a 100644
--- a/indoteknik_api/controllers/api_v1/stock_picking.py
+++ b/indoteknik_api/controllers/api_v1/stock_picking.py
@@ -4,6 +4,9 @@ from odoo.http import request
from pytz import timezone
from datetime import datetime
import json
+import logging
+
+_logger = logging.getLogger(__name__)
class StockPicking(controller.Controller):
@@ -143,30 +146,39 @@ class StockPicking(controller.Controller):
'name': picking_data.name
})
- # @http.route(prefix + 'webhook/biteship', type='json', auth='public', methods=['POST'], csrf=False)
- # def udpate_status_from_bitehsip(self, **kw):
- # try:
- # if not request.jsonrequest:
- # return "ok"
-
- # data = request.jsonrequest # Ambil data JSON dari request
- # event = data.get('event')
-
- # # Handle Event Berdasarkan Jenisnya
- # if event == "order.status":
- # self.process_order_status(data)
- # elif event == "order.price":
- # self.process_order_price(data)
- # elif event == "order.waybill_id":
- # self.process_order_waybill(data)
-
- # return {'success': True, 'message': f'Webhook {event} received'}
- # except Exception as e:
- # return {'success': False, 'message': str(e)}
-
- # @http.route(prefix + 'webhook/biteship', auth='public', methods=['POST'], csrf=False)
- # def udpate_status_from_bitehsip(self, **kw):
- # return "ok"
+ @http.route(prefix + 'webhook/biteship', type='json', auth='public', methods=['POST'], csrf=False)
+ def update_status_from_biteship(self, **kw):
+ _logger.info("Biteship Webhook: Request received at controller start (type='json').")
+
+ try:
+ # Karena type='json', Odoo secara otomatis akan mem-parsing JSON untuk Anda.
+ # 'data' akan berisi dictionary Python dari payload JSON Biteship.
+ data = request.jsonrequest
+
+ # Log ini akan menunjukkan payload yang diterima (sudah dalam bentuk dict)
+ _logger.info(f"Biteship Webhook: Parsed JSON data from request.jsonrequest: {json.dumps(data)}")
+
+ event = data.get('event')
+ if event:
+ _logger.info(f"Biteship Webhook: Processing event: {event}")
+ if event == "order.status":
+ self.process_order_status(data)
+ elif event == "order.price":
+ self.process_order_price(data)
+ elif event == "order.waybill_id":
+ self.process_order_waybill(data)
+ # Tambahkan logika untuk event lain jika ada
+ else:
+ _logger.info("Biteship Webhook: No specific event in payload. Likely an installation/verification ping or unknown event type.")
+
+ # Untuk route type='json', Anda cukup mengembalikan dictionary Python.
+ # Odoo akan secara otomatis mengonversinya menjadi respons JSON yang valid.
+ return {'status': 'ok'}
+
+ except Exception as e:
+ _logger.error(f"Biteship Webhook: Unhandled error during processing: {e}", exc_info=True)
+ # Untuk error, kembalikan dictionary error juga, Odoo akan mengonversinya ke JSON
+ return {'status': 'error', 'message': str(e)}
def process_order_status(self, data):
picking_model = request.env['stock.picking'].sudo().search([('biteship_id', '=', data.get('order_id'))],
diff --git a/indoteknik_custom/models/patch/__pycache__/__init__.py b/indoteknik_custom/models/patch/__init__.py
index 051b6537..051b6537 100644
--- a/indoteknik_custom/models/patch/__pycache__/__init__.py
+++ b/indoteknik_custom/models/patch/__init__.py
diff --git a/indoteknik_custom/models/patch/__pycache__/http_override.py b/indoteknik_custom/models/patch/http_override.py
index e1978edb..6bec1343 100644
--- a/indoteknik_custom/models/patch/__pycache__/http_override.py
+++ b/indoteknik_custom/models/patch/http_override.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
import odoo.http
import json
import logging