Skip to content

Commit

Permalink
[FIX] bug image extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudelva authored and bealdav committed Aug 14, 2024
1 parent d165af8 commit 8bac3cf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion zip_product_image/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Zip Product Images

|badge1| |badge2| |badge3|

Wizard to generate a zip images of selected products
Wizard to generate a zip images file of selected variant products.

This module is compatible with fs_product_multi_image module (from OCA/storage) but doesn't depends on it.

**Table of contents**

Expand Down
6 changes: 5 additions & 1 deletion zip_product_image/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
import imghdr

from odoo import api, models

LIMIT = 500
Expand Down Expand Up @@ -29,4 +31,6 @@ def _product_image_data(self):
if self.image:
return (base64.b64encode(self.image.getvalue()), self.image.extension)
return (False, False)
return (self.image_1920 or False, '.jpg')
image_data = base64.b64decode(self.image_1920)
image_type = imghdr.what(None, h=image_data)
return (self.image_1920 or False, f".{image_type}")
4 changes: 3 additions & 1 deletion zip_product_image/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Wizard to generate a zip images of selected products
Wizard to generate a zip images file of selected variant products.

This module is compatible with fs_product_multi_image module (from OCA/storage) but doesn't depends on it.
3 changes: 2 additions & 1 deletion zip_product_image/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ <h1 class="title">Zip Product Images</h1>
!! source digest: sha256:2918847fc8cec3732a3cbdc65ee2f5cb8dfef637c526f6cfd9424bcd6dccd6fc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/akretion/ak-odoo-incubator/tree/16.0/zip_product_image"><img alt="akretion/ak-odoo-incubator" src="https://img.shields.io/badge/github-akretion%2Fak--odoo--incubator-lightgray.png?logo=github" /></a></p>
<p>Wizard to generate a zip images of selected products</p>
<p>Wizard to generate a zip images file of selected variant products.</p>
<p>This module is compatible with fs_product_multi_image module (from OCA/storage) but doesn’t depends on it.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down
4 changes: 1 addition & 3 deletions zip_product_image/wizards/export_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def _get_zip_product_images(self, products):
name = ""
for field in self._product_field_names():
name = name or prd[field]
zip_file.writestr(
f"{name}{extension}", img_data
)
zip_file.writestr(f"{name}.{extension}", img_data)
else:
logger.warning(f"Product {prd.display_name} has no image")
if zip_file.filelist:
Expand Down

0 comments on commit 8bac3cf

Please sign in to comment.