Skip to content

Commit

Permalink
Merge PR #174 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
OCA-git-bot committed Nov 30, 2023
2 parents d29f007 + 4352bb1 commit bbf273d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion search_engine_image_thumbnail/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Search Engine Multi Image Thumbnail
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9e85a1605ac18dfb01ffa0f7c4864e227f61919d76b420bc140507ed4e9cadd5
!! source digest: sha256:27895102e7d95889ea4c09cf76a6791c37f8d4c59ff3120012a9a8673e7e701b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ def _is_model_valid_for_thumbnail(self, model_name):
@api.depends("model_id")
def _compute_field_id_domain(self):
for record in self:
model = self.env[record.model_id.model]
domain_fields = []
if record.model_id:
model = self.env[record.model_id.model]
domain_fields = model._fields.values()
names = []
for field in model._fields.values():
for field in domain_fields:
if self._is_field_valid_for_thumbnail(field):
names.append(field.name)
record.field_id_domain = json.dumps(
Expand Down
6 changes: 3 additions & 3 deletions search_engine_image_thumbnail/models/se_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SeIndex(models.Model):
image_field_thumbnail_size_ids = fields.One2many(
string="Thumbnail Sizes",
comodel_name="se.image.field.thumbnail.size",
compute="_compute_image_field_thumbnail_size_ids",
related="backend_id.image_field_thumbnail_size_ids",
)

@api.depends("backend_id.image_field_thumbnail_size_ids", "model_id")
Expand All @@ -23,9 +23,9 @@ def _compute_image_field_thumbnail_size_ids(self):
)
)

def _get_thumbnail_sizes(self, field_name):
def _get_thumbnail_sizes(self, record, field_name):
"""Return a list of thumbnail sizes for the given field_name"""
self.ensure_one()
return self.image_field_thumbnail_size_ids.filtered(
lambda r: r.field_name == field_name
lambda r: r.field_name == field_name and r.model == record._name
).mapped("size_ids")
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _get_thumbnail_sizes_by_size_for_field(
value is the thumbnail size record
"""
self.ensure_one()
sizes = index._get_thumbnail_sizes(field_name)
sizes = index._get_thumbnail_sizes(self, field_name)
if not sizes:
raise UserError(
_(
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions search_engine_image_thumbnail/readme/newsfragments/174.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*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.


*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.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Search Engine Multi Image Thumbnail</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9e85a1605ac18dfb01ffa0f7c4864e227f61919d76b420bc140507ed4e9cadd5
!! source digest: sha256:27895102e7d95889ea4c09cf76a6791c37f8d4c59ff3120012a9a8673e7e701b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/search-engine/tree/16.0/search_engine_image_thumbnail"><img alt="OCA/search-engine" src="https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/search-engine-16-0/search-engine-16-0-search_engine_image_thumbnail"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/search-engine&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module is a technical module with the purpose of easing the export
Expand Down

0 comments on commit bbf273d

Please sign in to comment.