Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4981][IMP] product_carousel_image_attachment #151

Open
wants to merge 10 commits into
base: 15.0
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions product_carousel_image_attachment/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.tools import ImageProcess

IMAGE_TYPES = ["image/png", "image/jpeg", "image/bmp", "image/gif"]


class IrAttachment(models.Model):
_inherit = "ir.attachment"

def _resize_image(self, datas):
ICP = self.env["ir.config_parameter"].sudo().get_param
max_resolution = (
"1025x1025" # Use 1025 instead of 1024 to enable the zoom feature
)
quality = int(ICP("base.image_autoresize_quality", 80))
img = ImageProcess(datas, verify_resolution=False)
w, h = img.image.size
nw, nh = map(int, max_resolution.split("x"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
max_resolution = (
"1025x1025" # Use 1025 instead of 1024 to enable the zoom feature
)
quality = int(ICP("base.image_autoresize_quality", 80))
img = ImageProcess(datas, verify_resolution=False)
w, h = img.image.size
nw, nh = map(int, max_resolution.split("x"))
max_resolution = (1025,1025) # Use 1025 instead of 1024 to enable the zoom feature
quality = int(ICP("base.image_autoresize_quality", 80))
img = ImageProcess(datas, verify_resolution=False)
w, h = img.image.size
nw, nh = max_resolution

I thought splitting the text is not necessary.

if w > nw or h > nh:
img = img.resize(nw, nh) # Resize the image
return img.image_base64(
quality=quality
) # Return the resized image as base64
return datas

@api.model_create_multi
def create(self, vals_list):
attachments = super(IrAttachment, self).create(vals_list)
Expand All @@ -22,20 +39,21 @@ def create(self, vals_list):
]
and not attachment.res_field
):
resized_image = self._resize_image(attachment.datas)
vals = {}
# assignment for pt and p
if attachment.res_model == "product.template":
pt = self.env["product.template"].browse(attachment.res_id)
vals = {
"name": attachment.name,
"image_1920": attachment.datas,
"image_1920": resized_image,
"product_tmpl_id": pt.id,
}
if attachment.res_model == "product.product":
p = self.env["product.product"].browse(attachment.res_id)
vals = {
"name": attachment.name,
"image_1920": attachment.datas,
"image_1920": resized_image,
"product_variant_id": p.id,
}
self.env["product.image"].sudo().create(vals)
Expand Down
Loading