diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-11-07 14:53:25 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-11-07 14:53:25 +0700 |
| commit | f0931f9b846f05a4debc967597bb54f91f9b640a (patch) | |
| tree | 879ead38afbe49d2cdc3f43845c6c5c925fbcf11 | |
| parent | 459e34a6f96ed12522036bb12da2e0488581c016 (diff) | |
<Miqdad> get image from envio
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 8fefcf81..798b4109 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -5,16 +5,16 @@ from collections import defaultdict from datetime import timedelta, datetime from datetime import timedelta, datetime as waktu from itertools import groupby -import pytz, requests, json, requests +import pytz, json from dateutil import parser import datetime import hmac import hashlib -import base64 import requests import time import logging import re +import base64 _logger = logging.getLogger(__name__) @@ -823,6 +823,37 @@ class StockPicking(models.Model): picking.envio_cod_value = data.get("cod_value", 0.0) picking.envio_cod_status = data.get("cod_status") + images_data = data.get('images', []) + for img in images_data: + image_url = img.get('image') + if image_url: + try: + # Download image from URL + img_response = requests.get(image_url) + img_response.raise_for_status() + + # Encode image to base64 + image_base64 = base64.b64encode(img_response.content) + + # Create attachment in Odoo + attachment = self.env['ir.attachment'].create({ + 'name': 'Envio Image', + 'type': 'binary', + 'datas': image_base64, + 'res_model': picking._name, + 'res_id': picking.id, + 'mimetype': 'image/png', + }) + + # Post log note with attachment + picking.message_post( + body="Image Envio", + attachment_ids=[attachment.id] + ) + + except Exception as e: + picking.message_post(body=f"Gagal ambil image Envio: {str(e)}") + # Menyimpan log terbaru logs = data.get("logs", []) if logs and isinstance(logs, list) and logs[0]: |
