Skip to content

Commit

Permalink
[ADD] attachment_image_resize
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 committed Nov 26, 2024
1 parent 7e6465e commit 14a83c5
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions attachment_image_resize/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions attachment_image_resize/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Attachment Image Resize",
"version": "15.0.1.0.0",
"author": "Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools",
"category": "Tools",
"license": "AGPL-3",
"depends": ["base"],
"data": ["views/res_config_settings_views.xml"],
"installable": True,
}
3 changes: 3 additions & 0 deletions attachment_image_resize/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import res_company
from . import res_config_settings
from . import ir_attachment
15 changes: 15 additions & 0 deletions attachment_image_resize/models/ir_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


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

def _get_max_resolution(self, values):
res_model = values.get("res_model")
models = self.env.company.attachment_image_resize_models
if res_model and models and res_model in models.split(","):
return self.env.company.attachment_image_max_resolution or "1920x1920"
return super()._get_max_resolution(values)
17 changes: 17 additions & 0 deletions attachment_image_resize/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

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."
)
attachment_image_max_resolution = fields.Char(
help="This resolution will be applied to the resizing of images"
" for the specified models."
)
21 changes: 21 additions & 0 deletions attachment_image_resize/models/res_config_settings.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.html).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

attachment_image_resize_models = fields.Char(
related="company_id.attachment_image_resize_models",
readonly=False,
help="When users attach images to these models, the images will be resized "
"based on the maximum resolution specified for attachments.",
)
attachment_image_max_resolution = fields.Char(
related="company_id.attachment_image_max_resolution",
readonly=False,
help="This resolution will be applied to the resizing of images"
" for the specified models.",
)
2 changes: 2 additions & 0 deletions attachment_image_resize/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#. Go to General Settings > Attachment Resize and enter the models you want to resize attachment images for in the 'Attachment Image Resize Models'.
#. In the same section, enter the maximum resolution you want to use for resizing attachment images in the 'Image Max Resolution'.
3 changes: 3 additions & 0 deletions attachment_image_resize/readme/DESCRIPTON.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module can resize attachment images with a customizable resolution for specific models, configurable per company.

Note: If the original image resolution is smaller than the customized resolution, it will not be resized.
60 changes: 60 additions & 0 deletions attachment_image_resize/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_stock_config_settings" model="ir.ui.view">
<field name="name">res.config.settings</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[hasclass('settings')]" position="inside">
<div
class="app_settings_block"
data-string="Attachment"
string="Attachment Resize"
>
<h2>Attachment Resize</h2>
<div
class="row mt16 o_settings_container"
name="catalog_setting_container"
>
<div class="col-12 col-lg-6 o_setting_box" id="variant_options">
<div class="o_setting_left_pane">
</div>
<div class="o_setting_right_pane">
<div class="content-group">
<div>
<div>
<label
for="attachment_image_resize_models"
string="Attachment Image Resize Models"
class="o_light_label"
style="vertical-align: top;"
/>
<field
name="attachment_image_resize_models"
placeholder="product.product,sale.order"
style="display:inline-block;"
/>
</div>
<div>
<label
for="attachment_image_max_resolution"
string="Image Max Resolution"
class="o_light_label"
style="vertical-align: top;"
/>
<field
name="attachment_image_max_resolution"
placeholder="1025x1025"
style="display:inline-block;"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/attachment_image_resize/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 14a83c5

Please sign in to comment.