-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e6465e
commit 14a83c5
Showing
11 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
attachment_image_resize/views/res_config_settings_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
1 change: 1 addition & 0 deletions
1
setup/attachment_image_resize/odoo/addons/attachment_image_resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../attachment_image_resize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |