Skip to content

Commit

Permalink
adj
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Nov 25, 2024
1 parent a87ad02 commit c21c928
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
1 change: 1 addition & 0 deletions product_carousel_image_attachment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"category": "Tools",
"license": "AGPL-3",
"depends": ["website_sale"],
"data": ["data/scheduler.xml"],
"installable": True,
}
17 changes: 17 additions & 0 deletions product_carousel_image_attachment/data/scheduler.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<!-- This cron is intended for the initial update of existing images, therefore is expected to
be disabled in normal circumstances. -->
<record model="ir.cron" id="resize_product_image">
<field name="name">Resize Extra Product Image</field>
<field name="model_id" ref="model_product_image" />
<field name="state">code</field>
<field name="code">model._cron_resize_product_image(1000)</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="active" eval="False" />
</record>
</odoo>
1 change: 1 addition & 0 deletions product_carousel_image_attachment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import ir_attachment
from . import product_image
16 changes: 9 additions & 7 deletions product_carousel_image_attachment/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
class IrAttachment(models.Model):
_inherit = "ir.attachment"

@api.model
def _resize_image(self, datas):
ICP = self.env["ir.config_parameter"].sudo().get_param
# Use 1025 instead of 1024 to enable the zoom feature.
# Define a static value instead of modifying the system parameter
# 'base.image_autoresize_extensions' to avoid
# affecting other image fields.
nw, nh = (1025, 1025)
quality = int(ICP("base.image_autoresize_quality", 80))
# Use 1025 instead of 1024 to enable the zoom feature
max_resolution = (1025, 1025)
img = ImageProcess(datas, verify_resolution=False)
w, h = img.image.size
nw, nh = map(int, max_resolution.split("x"))
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
# Use odoo standard resize
img = img.resize(nw, nh)
return img.image_base64(quality=quality)
return datas

@api.model_create_multi
Expand Down
21 changes: 21 additions & 0 deletions product_carousel_image_attachment/models/product_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class ProductImage(models.Model):
_inherit = "product.image"

@api.model
def _cron_resize_product_image(self, limit):
images = self.sudo().search([], limit=limit)
for image in images:
if image.image_1920:
image.image_1920 = self.env["ir.attachment"]._resize_image(
image.image_1920
)
if len(images) == limit:
self.env.ref(
"product_carousel_image_attachment.resize_product_image"
)._trigger()

0 comments on commit c21c928

Please sign in to comment.