Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Aug 9, 2024
1 parent 43a4251 commit ab20875
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 7 additions & 0 deletions zip_product_image/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ def _generate_image_zipfile(self):
.create({})
._get_zip_product_images(self.browse(prd_ids))
)

def _product_image_buffer(self):
self.ensure_one()
if "fs.product.image" in self.env.registry:
# Here fs_product_multi_image is installed
return self.image
return self.image_1920
7 changes: 1 addition & 6 deletions zip_product_image/wizards/export_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ class ZipProductImage(models.TransientModel):
def _get_zip_product_images(self, products):
"""Generate a zip file with the images of the products."""
zip_buffer = BytesIO()
img_field = self._product_image_field()
with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, False) as zip_file:
for prd in products:
img_data = prd[img_field] and base64.b64decode(prd[img_field])
img_data = base64.b64decode(prd._product_image_buffer())
if img_data:
name = ""
for field in self._product_field_names():
Expand All @@ -45,7 +44,3 @@ def _product_field_names(self):

def _product_image_extension(self):
return "png"

def _product_image_field(self):
"Can be different is used with storage repo"
return "image_1920"
2 changes: 1 addition & 1 deletion zip_product_image/wizards/export_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</record>

<record id="action_zip_product_image" model="ir.actions.server">
<field name="name">Export images</field>
<field name="name">📎 Zip images export</field>
<field name="model_id" ref="model_product_product" />
<field name="binding_model_id" ref="model_product_product" />
<field name="state">code</field>
Expand Down

0 comments on commit ab20875

Please sign in to comment.