[FIX] data_nature_importer: move image encoding into utils
This commit is contained in:
parent
461fc34f1b
commit
f7b25ea02e
2 changed files with 5 additions and 5 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
import base64
|
|
||||||
|
|
||||||
from odoo import models
|
from odoo import models
|
||||||
|
|
||||||
from .. import utils as dn_utils
|
from .. import utils as dn_utils
|
||||||
|
|
@ -12,7 +10,7 @@ class ProductTemplate(models.Model):
|
||||||
for product in self:
|
for product in self:
|
||||||
image_data = product._get_dn_image()
|
image_data = product._get_dn_image()
|
||||||
if image_data:
|
if image_data:
|
||||||
product.image_1920 = base64.b64encode(image_data).decode("ascii")
|
product.image_1920 = image_data
|
||||||
|
|
||||||
def _get_dn_metadata(self):
|
def _get_dn_metadata(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
|
@ -29,5 +27,5 @@ class ProductTemplate(models.Model):
|
||||||
image_id = metadata.get("images")[0].get("id")
|
image_id = metadata.get("images")[0].get("id")
|
||||||
image_data = dn_utils.get_datanature_image(self, image_id, token=None)
|
image_data = dn_utils.get_datanature_image(self, image_id, token=None)
|
||||||
if image_data:
|
if image_data:
|
||||||
return base64.b64encode(image_data).decode("ascii")
|
return image_data
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import base64
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
@ -227,5 +228,6 @@ def get_datanature_image(self, image_id, token=None):
|
||||||
headers = {"Authorization": f"Bearer {token}", "accept": "application/octet-stream"}
|
headers = {"Authorization": f"Bearer {token}", "accept": "application/octet-stream"}
|
||||||
response = requests.get(url, headers=headers, timeout=30)
|
response = requests.get(url, headers=headers, timeout=30)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.content
|
image = base64.b64encode(response.content).decode("ascii")
|
||||||
|
return image
|
||||||
raise UserError(_("Failed to fetch DataNature image for ID: %s") % image_id)
|
raise UserError(_("Failed to fetch DataNature image for ID: %s") % image_id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue