Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ exclude: |
^connector_algolia/|
^connector_elasticsearch/|
^connector_search_engine_serializer_ir_export/|
^search_engine_image_thumbnail/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
Expand Down
78 changes: 38 additions & 40 deletions search_engine_image_thumbnail/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Search Engine Multi Image Thumbnail
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github
:target: https://github.com/OCA/search-engine/tree/16.0/search_engine_image_thumbnail
:target: https://github.com/OCA/search-engine/tree/18.0/search_engine_image_thumbnail
:alt: OCA/search-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/search-engine-16-0/search-engine-16-0-search_engine_image_thumbnail
:target: https://translation.odoo-community.org/projects/search-engine-18-0/search-engine-18-0-search_engine_image_thumbnail
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/search-engine&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/search-engine&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -77,18 +77,18 @@ thumbnails from an image you want to index.
Behind the scenes, this module extend the ``se.indexable.recor`` model
by adding 2 new methods:

- ``_get_or_create_thumbnails_for_multi_images``: This method is used
to get or create thumbnails for a set of images.
- ``_get_or_create_thumbnails_for_image``: This method is used to get
or create thumbnails for a single image.
- ``_get_or_create_thumbnails_for_multi_images``: This method is used to
get or create thumbnails for a set of images.
- ``_get_or_create_thumbnails_for_image``: This method is used to get or
create thumbnails for a single image.

Thanks to these methods, you can easily generate thumbnails for images
stored into odoo through three different ways:

- A relational field referencing record inheriting from
``fs.image.relation.mixin``.
- An odoo's Image field.
- An FSImage field.
- A relational field referencing record inheriting from
``fs.image.relation.mixin``.
- An odoo's Image field.
- An FSImage field.

The sizes of the thumbnails generated by these methods are configured
through the creation of a new record into the ``se.thumbnail.size``
Expand Down Expand Up @@ -189,48 +189,46 @@ Changelog
Bugfixes
^^^^^^^^

- Add new config parameter on the search engine backend to allow the
user to specify if the serialization of a record should fail if
thumbnails are requested but no thumbnail sizes are defined for the
model and field for which it' requested. Defaults to False (i.e.
don't fail).
(`#176 <https://github.com/OCA/search-engine/issues/176>`__)
- Add new config parameter on the search engine backend to allow the
user to specify if the serialization of a record should fail if
thumbnails are requested but no thumbnail sizes are defined for the
model and field for which it' requested. Defaults to False (i.e. don't
fail). (`#176 <https://github.com/OCA/search-engine/issues/176>`__)

16.0.1.0.4 (2024-04-09)
-----------------------

Bugfixes
^^^^^^^^

- *Fixes image sizes lookups.*
- *Fixes image sizes lookups.*

When serializing a record and generating thumbnails, the thumbnail
sizes are looked up on the index. Prior to this change, only sizes
defined for the model associated with the current index were looked
up. This means that if you tried to serialize a nested record that
had an image field that was defined on a different model, the
thumbnail size was not found and an error was thrown. The lookup
method takes now the record for which the thumbnail is being
generated as an argument, so that the correct model can be used to
look up the thumbnail size. You still need to define the thumbnail
sizes for each model serialized in the index.
When serializing a record and generating thumbnails, the thumbnail
sizes are looked up on the index. Prior to this change, only sizes
defined for the model associated with the current index were looked
up. This means that if you tried to serialize a nested record that had
an image field that was defined on a different model, the thumbnail
size was not found and an error was thrown. The lookup method takes
now the record for which the thumbnail is being generated as an
argument, so that the correct model can be used to look up the
thumbnail size. You still need to define the thumbnail sizes for each
model serialized in the index.

*Fixes UI error when creating a new thumbnail size.*
*Fixes UI error when creating a new thumbnail size.*

When creating a new record, the UI was throwing an error. This was
due to the computations of the domain to apply to restrict the
choices of the possible image fields. When the record is new, no
model is set, so the domain for the field must be empty. This is now
handled correctly.
(`#174 <https://github.com/OCA/search-engine/issues/174>`__)
When creating a new record, the UI was throwing an error. This was due
to the computations of the domain to apply to restrict the choices of
the possible image fields. When the record is new, no model is set, so
the domain for the field must be empty. This is now handled correctly.
(`#174 <https://github.com/OCA/search-engine/issues/174>`__)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/search-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/search-engine/issues/new?body=module:%20search_engine_image_thumbnail%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/search-engine/issues/new?body=module:%20search_engine_image_thumbnail%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -245,9 +243,9 @@ Authors
Contributors
------------

- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu/)
- Mohamed Alkobrosli alkobroslymohamed@gmail.com
(https://www.kobros-tech.com/)
- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu/)
- Mohamed Alkobrosli alkobroslymohamed@gmail.com
(https://www.kobros-tech.com/)

Other credits
-------------
Expand Down Expand Up @@ -277,6 +275,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-lmignon|

This module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/16.0/search_engine_image_thumbnail>`_ project on GitHub.
This module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/18.0/search_engine_image_thumbnail>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
8 changes: 3 additions & 5 deletions search_engine_image_thumbnail/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

{
"name": "Search Engine Multi Image Thumbnail",
"summary": """
Generate thumbnails for binded record""",
"version": "16.0.1.0.7",
"summary": "Generate thumbnails for binded record",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/search-engine",
Expand All @@ -29,6 +28,5 @@
"views/se_thumbnail.xml",
"views/se_thumbnail_size.xml",
],
"demo": [],
"installable": False,
"installable": True,
}
1 change: 0 additions & 1 deletion search_engine_image_thumbnail/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class IrAttachment(models.Model):

_inherit = "ir.attachment"

se_thumbnail_ids = fields.One2many(
Expand Down
1 change: 0 additions & 1 deletion search_engine_image_thumbnail/models/se_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class SeBackend(models.Model):

_inherit = "se.backend"

image_field_thumbnail_size_ids = fields.One2many(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class SeImageFieldThumbnailSize(models.Model):

_name = "se.image.field.thumbnail.size"
_description = "Index Thumbnail Size"

Expand Down
1 change: 0 additions & 1 deletion search_engine_image_thumbnail/models/se_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class SeIndex(models.Model):

_inherit = "se.index"

image_field_thumbnail_size_ids = fields.One2many(
Expand Down
12 changes: 7 additions & 5 deletions search_engine_image_thumbnail/models/se_indexable_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from collections import OrderedDict

from odoo import _, fields, models
from odoo import fields, models
from odoo.exceptions import UserError

from odoo.addons.connector_search_engine.models.se_index import SeIndex
Expand Down Expand Up @@ -32,7 +32,8 @@ def _get_or_create_thumbnails_for_multi_images(
:param field_name: The name of the field
:return: a ordered dictionary where the key is the original image
relation and the value is a list of tuple(se.thumbnail.size, se.thumbnail)
(The order of the dict is the order of the images in the original Odoo record)
(The order of the dict is the order of the images in the original
Odoo record)

"""
self.ensure_one()
Expand All @@ -48,7 +49,7 @@ def _get_or_create_thumbnails_for_multi_images(
thumbnails_by_image = se_tumbnail_model.get_or_create_thumbnails(
*images.mapped("image"),
sizes=thumbnail_sizes_by_size.keys(),
base_name=self._get_image_url_key(index, field_name)
base_name=self._get_image_url_key(index, field_name),
)
res = OrderedDict[
FsImageRelationMixin, list[tuple[SeThumbnailSize, FsImageThumbnailMixin]]
Expand All @@ -69,7 +70,8 @@ def _get_or_create_thumbnails_for_image(
"""Create a thumbnail for an image field.

:param index: The index where the record should be added
:param field_name: The name of the field. (should be a fields.Image or FSImage) field
:param field_name: The name of the field. (should be a fields.Image or
FSImage) field
:return: a list of tuple(se.thumbnail.size, fs.image.thumbnail.mixi)
"""
thumbnail_sizes_by_size = self._get_thumbnail_sizes_by_size_for_field(
Expand Down Expand Up @@ -114,7 +116,7 @@ def _get_thumbnail_sizes_by_size_for_field(
sizes = index._get_thumbnail_sizes(self, field_name)
if not sizes and index.backend_id.fails_if_no_thumbail_size:
raise UserError(
_(
self.env._(
"No thumbnail sizes defined for %(model)s.%(field)s",
field=field_name,
model=self._name,
Expand Down
1 change: 0 additions & 1 deletion search_engine_image_thumbnail/models/se_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class SeThumbnail(models.Model):

_name = "se.thumbnail"
_inherit = "fs.image.thumbnail.mixin"
_description = "Indexed Image Thumbnail"
5 changes: 1 addition & 4 deletions search_engine_image_thumbnail/models/se_thumbnail_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class SeThumbnailSize(models.Model):

_name = "se.thumbnail.size"
_description = "Thumbnail Size"

Expand All @@ -17,6 +16,4 @@ class SeThumbnailSize(models.Model):
@api.depends("size_x", "size_y")
def _compute_display_name(self):
for record in self:
record.display_name = "{} ({}x{})".format(
record.name, record.size_x, record.size_y
)
record.display_name = f"{record.name} ({record.size_x}x{record.size_y})"
3 changes: 3 additions & 0 deletions search_engine_image_thumbnail/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!-- Copyright 2023 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.model.access" id="se_image_field_thumbnail_size_access_read">
<field name="name">se.image.field.thumbnail.size access read</field>
<field name="model_id" ref="model_se_image_field_thumbnail_size" />
Expand All @@ -25,5 +24,4 @@
<field name="perm_write" eval="1" />
<field name="perm_unlink" eval="1" />
</record>

</odoo>
2 changes: 0 additions & 2 deletions search_engine_image_thumbnail/security/se_thumbnail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!-- Copyright 2023 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.model.access" id="se_thumbnail_access_read">
<field name="name">se.thumbnail access read</field>
<field name="model_id" ref="model_se_thumbnail" />
Expand All @@ -12,5 +11,4 @@
<field name="perm_write" eval="0" />
<field name="perm_unlink" eval="0" />
</record>

</odoo>
2 changes: 0 additions & 2 deletions search_engine_image_thumbnail/security/se_thumbnail_size.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!-- Copyright 2023 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.model.access" id="se_thumbnail_size_access_read">
<field name="name">se.thumbnail.size access read</field>
<field name="model_id" ref="model_se_thumbnail_size" />
Expand All @@ -25,5 +24,4 @@
<field name="perm_write" eval="1" />
<field name="perm_unlink" eval="1" />
</record>

</odoo>
Loading
Loading