[168][IMP] data_nature_importer: add extra product media
This commit is contained in:
parent
b1cfa51e92
commit
bd1f62b327
5 changed files with 37 additions and 21 deletions
|
|
@ -41,7 +41,8 @@ Changelog
|
|||
- 16.0.1.0.0: Initial module.
|
||||
- 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.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
|
||||
===========
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
"author": "BAKEUP",
|
||||
"website": "https://www.bakeup.org",
|
||||
"category": "product",
|
||||
"version": "16.0.1.0.2",
|
||||
"depends": ["product", "queue_job"],
|
||||
"version": "16.0.1.2.0",
|
||||
"depends": ["product", "queue_job", "website_sale"],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"views/product_template_views.xml",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class ProductTemplate(models.Model):
|
|||
|
||||
def action_sync_datanature_image(self):
|
||||
for product in self:
|
||||
product.with_delay()._sync_datanature_image()
|
||||
product.with_delay()._sync_dn_images()
|
||||
|
||||
def _get_dn_metadata(self):
|
||||
self.ensure_one()
|
||||
|
|
@ -19,7 +19,7 @@ class ProductTemplate(models.Model):
|
|||
return False
|
||||
return metadata[0]
|
||||
|
||||
def _get_dn_image(self):
|
||||
def _sync_dn_images(self):
|
||||
self.ensure_one()
|
||||
metadata = self._get_dn_metadata()
|
||||
if not metadata or not metadata.get("images"):
|
||||
|
|
@ -28,17 +28,30 @@ class ProductTemplate(models.Model):
|
|||
if not images:
|
||||
return False
|
||||
image_id = None
|
||||
for img in images:
|
||||
if img.get("default") == "true":
|
||||
image_id = img.get("id")
|
||||
break
|
||||
for image in images:
|
||||
image_id = image.get("id")
|
||||
image_data = dn_utils.get_datanature_image(self, image_id, token=None)
|
||||
if image_data:
|
||||
return image_data
|
||||
return False
|
||||
|
||||
def _sync_datanature_image(self):
|
||||
self.ensure_one()
|
||||
image_data = self._get_dn_image()
|
||||
if image_data:
|
||||
if not image_data:
|
||||
continue
|
||||
if image.get("default") == "true":
|
||||
self.image_1920 = image_data
|
||||
else:
|
||||
ProductImage = self.env["product.image"]
|
||||
if (
|
||||
ProductImage.search_count(
|
||||
[
|
||||
("product_tmpl_id", "=", self.id),
|
||||
("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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
- 16.0.1.0.0: Initial module.
|
||||
- 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.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
|
||||
|
|
@ -384,7 +384,8 @@ ul.auto-toc {
|
|||
<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.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>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
|
|
|
|||
Loading…
Reference in a new issue