diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-07-05 15:54:17 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-07-05 15:54:17 +0700 |
| commit | a78f8184c2e7d45a65315eff0ea354996adb9cce (patch) | |
| tree | 0e925c10c3f4844132f742f997d6eeab426b0839 | |
| parent | 9357a194e8b85343160f30b131c5802be954650d (diff) | |
(andri) info tambahan webhook
| -rw-r--r-- | indoteknik_api/controllers/api_v1/stock_picking.py | 44 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 20 |
2 files changed, 48 insertions, 16 deletions
diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py index 0525adc3..85b0fbba 100644 --- a/indoteknik_api/controllers/api_v1/stock_picking.py +++ b/indoteknik_api/controllers/api_v1/stock_picking.py @@ -213,22 +213,38 @@ class StockPicking(controller.Controller): def process_order_price(self, data): - picking_model = request.env['stock.picking'].sudo().search([('biteship_id', '=', data.get('order_id'))], - limit=1) - if not picking_model: + picking = request.env['stock.picking'].sudo().search([('biteship_id', '=', data.get('order_id'))], limit=1) + + if not picking: _logger.warning(f"Tidak ditemukan picking untuk order_id {data.get('order_id')}") return - picking_model.write({ - 'biteship_shipping_price': data.get('price') - }) + picking.log_biteship_event_from_webhook( + status='order.price', + timestamp=data.get('updated_at') or datetime.utcnow().isoformat(), + description='Biaya pengiriman telah diperbarui berdasarkan informasi terbaru dari Biteship.', + extra_data={ + "order_price": data.get("price") + } + ) + def process_order_waybill(self, data): - picking_model = request.env['stock.picking'].sudo().search([('biteship_id', '=', data.get('order_id'))], - limit=1) - if picking_model: - picking_model.write({ - 'biteship_waybill_id': data.get('courier_waybill_id'), - 'delivery_tracking_no': data.get('courier_waybill_id'), - 'biteship_tracking_id': data.get('courier_tracking_id') - }) + picking = request.env['stock.picking'].sudo().search([ + ('biteship_id', '=', data.get('order_id')) + ], limit=1) + + if not picking: + _logger.warning(f"Tidak ditemukan picking untuk order_id {data.get('order_id')}") + return + + picking.log_biteship_event_from_webhook( + status='order.waybill_id', + timestamp=data.get('updated_at') or datetime.utcnow().isoformat(), + description="Nomor waybill dan tracking diperbarui melalui Biteship.", + extra_data={ + "tracking_id": data.get("courier_tracking_id"), + "waybill_id": data.get("courier_waybill_id") + } + ) + diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index e411aee6..6e8c1067 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1866,6 +1866,7 @@ class StockPicking(models.Model): _logger.warning(f"[Webhook] Gagal konversi waktu: {e}") dt = datetime.utcnow() + # Penanganan status pengiriman if status == "picked" and not self.driver_departure_date: updated_fields["driver_departure_date"] = fields.Datetime.to_string(dt) if status == "delivered" and not self.driver_arrival_date: @@ -1875,7 +1876,9 @@ class StockPicking(models.Model): if shipping_status and self.shipping_status != shipping_status: updated_fields["shipping_status"] = shipping_status + # Penanganan extra data dari webhook if extra_data: + # Informasi kurir if extra_data.get("courier_driver_name"): updated_fields["biteship_driver_name"] = extra_data["courier_driver_name"] if extra_data.get("courier_driver_phone"): @@ -1884,11 +1887,21 @@ class StockPicking(models.Model): updated_fields["biteship_driver_plate_number"] = extra_data["courier_driver_plate_number"] if extra_data.get("courier_link"): updated_fields["biteship_courier_link"] = extra_data["courier_link"] + # Informasi harga if extra_data.get("order_price"): updated_fields["biteship_shipping_price"] = extra_data["order_price"] + # Status mentah dari Biteship if extra_data.get("status"): updated_fields["biteship_shipping_status"] = extra_data["status"] + # Tambahan untuk handle order.waybill_id + if extra_data.get("tracking_id"): + updated_fields["biteship_tracking_id"] = extra_data["tracking_id"] + updated_fields["delivery_tracking_no"] = extra_data["tracking_id"] + if extra_data.get("waybill_id"): + updated_fields["biteship_waybill_id"] = extra_data["waybill_id"] + + # Konversi waktu lokal untuk log try: dt_parsed = parser.parse(timestamp) if dt_parsed.tzinfo is None: @@ -1897,13 +1910,16 @@ class StockPicking(models.Model): except Exception: dt_local = dt.astimezone(pytz.timezone("Asia/Jakarta")) + # Format pesan log desc_clean = ' '.join(description.strip().split()) log_line = f"[TRACKING] {status} - {dt_local.strftime('%d %b %Y %H:%M')}:<br/>{desc_clean}" + # Hindari log duplikat if not self._has_existing_log(log_line): - self.with_user(15172).message_post(body=log_line) # user biteship test - # self.with_user(15710).message_post(body=log_line) # user biteship live + self.with_user(15172).message_post(body=log_line) # Biteship user + # self.with_user(15710).message_post(body=log_line) # Biteship user live + # Update field-field terkait if updated_fields: self.write(updated_fields) _logger.info(f"[Webhook] Updated fields on picking {self.name}: {updated_fields}") |
