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][ADD] attachment_image_resize #49

Open
wants to merge 2 commits into
base: 15.0
Choose a base branch
from

Conversation

AungKoKoLin1997
Copy link
Contributor

@AungKoKoLin1997 AungKoKoLin1997 commented Nov 26, 2024

@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as draft November 26, 2024 08:49
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-add-attachment_image_resize branch 2 times, most recently from b317a75 to b46bb2a Compare November 27, 2024 07:21
@AungKoKoLin1997 AungKoKoLin1997 marked this pull request as ready for review November 27, 2024 07:21
@AungKoKoLin1997
Copy link
Contributor Author

@yostashiro @kanda999 Please review this PR.

Comment on lines 24 to 27
ICP = self.env["ir.config_parameter"].sudo().get_param
max_resolution = self.env.company.attachment_image_max_resolution or "1920x1920"
max_width, max_height = map(int, max_resolution.split("x"))
quality = int(ICP("base.image_autoresize_quality", 80))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ICP = self.env["ir.config_parameter"].sudo().get_param
max_resolution = self.env.company.attachment_image_max_resolution or "1920x1920"
max_width, max_height = map(int, max_resolution.split("x"))
quality = int(ICP("base.image_autoresize_quality", 80))
max_resolution = self.env.company.attachment_image_max_resolution or "1920x1920"
max_width, max_height = map(int, max_resolution.split("x"))
ICP = self.env["ir.config_parameter"].sudo().get_param
quality = int(ICP("base.image_autoresize_quality", 80))

return datas

@api.model
def _cron_resize_attachment_image(self, limit):
Copy link
Member

Choose a reason for hiding this comment

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

Move this method to the bottom.

and mimetype in IMAGE_TYPES
):
# Resize raw binary or Base64 data
if "raw" in values and values["raw"]:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if "raw" in values and values["raw"]:
if values.get("raw"):

# Resize raw binary or Base64 data
if "raw" in values and values["raw"]:
values["raw"] = self._resize_image(values["raw"], is_raw=True)
elif "datas" in values and values["datas"]:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
elif "datas" in values and values["datas"]:
elif values.get("datas"):

values["raw"] = self._resize_image(values["raw"], is_raw=True)
elif "datas" in values and values["datas"]:
values["datas"] = self._resize_image(values["datas"], is_raw=False)
return super(IrAttachment, self).create(vals_list)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return super(IrAttachment, self).create(vals_list)
return super().create(vals_list)

Comment on lines +14 to +17
attachment_image_max_resolution = fields.Char(
help="This resolution will be applied to the resizing of images"
" for the specified models."
)
Copy link
Member

Choose a reason for hiding this comment

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

Another approach is to have this in ir.model, which makes the size control more granular.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we talked, we will use current approach to avoid same configuration for each model and there may be rare case to use each resolution for each model.

Comment on lines +10 to +13
attachment_image_resize_models = fields.Char(
help="When users attach images to these models, the images will be resized "
"based on the maximum resolution specified for attachments."
)
Copy link
Member

Choose a reason for hiding this comment

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

If we keep this field, help text should contain an example of how it should be populated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the placeholder for this.

):
# Resize raw binary or Base64 data
if "raw" in values and values["raw"]:
values["raw"] = self._resize_image(values["raw"], is_raw=True)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
values["raw"] = self._resize_image(values["raw"], is_raw=True)
values["raw"] = self._resize_image(values["raw"], is_raw=True)
values["resize_done"] = True

if "raw" in values and values["raw"]:
values["raw"] = self._resize_image(values["raw"], is_raw=True)
elif "datas" in values and values["datas"]:
values["datas"] = self._resize_image(values["datas"], is_raw=False)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
values["datas"] = self._resize_image(values["datas"], is_raw=False)
values["datas"] = self._resize_image(values["datas"], is_raw=False)
values["resize_done"] = True

Comment on lines 70 to 73
if len(attachments) == limit:
self.env.ref(
"attachment_image_resize.resize_attachment_image"
)._trigger()
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason we are reviving this approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I revived this because this module will be OCA module and I don't want to make user runs and check there is still attachment that haven't resized and rerun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants