diff --git a/data_nature_importer/README.rst b/data_nature_importer/README.rst index 3cbb83c..d498167 100644 --- a/data_nature_importer/README.rst +++ b/data_nature_importer/README.rst @@ -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 =========== diff --git a/data_nature_importer/__manifest__.py b/data_nature_importer/__manifest__.py index 458e1b5..faddb10 100644 --- a/data_nature_importer/__manifest__.py +++ b/data_nature_importer/__manifest__.py @@ -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", diff --git a/data_nature_importer/models/product_template.py b/data_nature_importer/models/product_template.py index 002a041..9474e61 100644 --- a/data_nature_importer/models/product_template.py +++ b/data_nature_importer/models/product_template.py @@ -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 - 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: - self.image_1920 = image_data + for image in images: + image_id = image.get("id") + image_data = dn_utils.get_datanature_image(self, image_id, token=None) + 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 diff --git a/data_nature_importer/readme/HISTORY.rst b/data_nature_importer/readme/HISTORY.rst index bbebf27..b6aba38 100644 --- a/data_nature_importer/readme/HISTORY.rst +++ b/data_nature_importer/readme/HISTORY.rst @@ -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 \ No newline at end of file diff --git a/data_nature_importer/static/description/index.html b/data_nature_importer/static/description/index.html index cce3dcf..b38a634 100644 --- a/data_nature_importer/static/description/index.html +++ b/data_nature_importer/static/description/index.html @@ -384,7 +384,8 @@ ul.auto-toc {