[168][IMP] data_nature_importer: add extra product media

This commit is contained in:
Niels Göttsch 2026-01-27 21:18:54 +01:00 committed by madmooose
parent b1cfa51e92
commit bd1f62b327
5 changed files with 37 additions and 21 deletions

View file

@ -41,7 +41,8 @@ Changelog
- 16.0.1.0.0: Initial module. - 16.0.1.0.0: Initial module.
- 16.0.1.0.1: Catch empty metadata response in _get_dn_metadata - 16.0.1.0.1: Catch empty metadata response in _get_dn_metadata
- 16.0.1.1.0: Add Queue Job support and move to server action - 16.0.1.1.0: Add Queue Job support and move to server action
- 16.0.1.0.2: Use default image as product image - 16.0.1.1.1: Use default image as product image
- 16.0.1.2.0: Add Extra Product Media support
Bug Tracker Bug Tracker
=========== ===========

View file

@ -4,8 +4,8 @@
"author": "BAKEUP", "author": "BAKEUP",
"website": "https://www.bakeup.org", "website": "https://www.bakeup.org",
"category": "product", "category": "product",
"version": "16.0.1.0.2", "version": "16.0.1.2.0",
"depends": ["product", "queue_job"], "depends": ["product", "queue_job", "website_sale"],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",
"views/product_template_views.xml", "views/product_template_views.xml",

View file

@ -8,7 +8,7 @@ class ProductTemplate(models.Model):
def action_sync_datanature_image(self): def action_sync_datanature_image(self):
for product in self: for product in self:
product.with_delay()._sync_datanature_image() product.with_delay()._sync_dn_images()
def _get_dn_metadata(self): def _get_dn_metadata(self):
self.ensure_one() self.ensure_one()
@ -19,7 +19,7 @@ class ProductTemplate(models.Model):
return False return False
return metadata[0] return metadata[0]
def _get_dn_image(self): def _sync_dn_images(self):
self.ensure_one() self.ensure_one()
metadata = self._get_dn_metadata() metadata = self._get_dn_metadata()
if not metadata or not metadata.get("images"): if not metadata or not metadata.get("images"):
@ -28,17 +28,30 @@ class ProductTemplate(models.Model):
if not images: if not images:
return False return False
image_id = None image_id = None
for img in images: for image in images:
if img.get("default") == "true": image_id = image.get("id")
image_id = img.get("id") image_data = dn_utils.get_datanature_image(self, image_id, token=None)
break if not image_data:
image_data = dn_utils.get_datanature_image(self, image_id, token=None) continue
if image_data: if image.get("default") == "true":
return image_data self.image_1920 = image_data
return False else:
ProductImage = self.env["product.image"]
def _sync_datanature_image(self): if (
self.ensure_one() ProductImage.search_count(
image_data = self._get_dn_image() [
if image_data: ("product_tmpl_id", "=", self.id),
self.image_1920 = image_data ("name", "=", f"DATA Nature Image: {image_id}"),
]
)
> 0
):
continue
ProductImage.create(
{
"name": f"DATA Nature Image: {image_id}",
"product_tmpl_id": self.id,
"image_1920": image_data,
}
)
return True

View file

@ -1,4 +1,5 @@
- 16.0.1.0.0: Initial module. - 16.0.1.0.0: Initial module.
- 16.0.1.0.1: Catch empty metadata response in _get_dn_metadata - 16.0.1.0.1: Catch empty metadata response in _get_dn_metadata
- 16.0.1.1.0: Add Queue Job support and move to server action - 16.0.1.1.0: Add Queue Job support and move to server action
- 16.0.1.0.2: Use default image as product image - 16.0.1.1.1: Use default image as product image
- 16.0.1.2.0: Add Extra Product Media support

View file

@ -384,7 +384,8 @@ ul.auto-toc {
<li>16.0.1.0.0: Initial module.</li> <li>16.0.1.0.0: Initial module.</li>
<li>16.0.1.0.1: Catch empty metadata response in _get_dn_metadata</li> <li>16.0.1.0.1: Catch empty metadata response in _get_dn_metadata</li>
<li>16.0.1.1.0: Add Queue Job support and move to server action</li> <li>16.0.1.1.0: Add Queue Job support and move to server action</li>
<li>16.0.1.0.2: Use default image as product image</li> <li>16.0.1.1.1: Use default image as product image</li>
<li>16.0.1.2.0: Add Extra Product Media support</li>
</ul> </ul>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">