Skip to content

Commit

Permalink
[FIX] search_engine_image_thumbnail: fix the domain type for image fi…
Browse files Browse the repository at this point in the history
…elds filter
  • Loading branch information
kobros-tech committed Oct 7, 2024
1 parent 3f452b8 commit 81463a3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 40 deletions.
12 changes: 6 additions & 6 deletions search_engine_image_thumbnail/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-04-15 10:37+0000\n"
"PO-Revision-Date: 2024-10-07 18:22+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
Expand Down Expand Up @@ -59,11 +59,6 @@ msgstr "Creato il"
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: search_engine_image_thumbnail
#: model:ir.model.fields,field_description:search_engine_image_thumbnail.field_se_image_field_thumbnail_size__field_id_domain
msgid "Domain to select images field"
msgstr "Dminio per selezionare il campo immagine"

#. module: search_engine_image_thumbnail
#: model:ir.model.fields,field_description:search_engine_image_thumbnail.field_se_backend__fails_if_no_thumbail_size
msgid "Fail if no thumbnail size"
Expand Down Expand Up @@ -105,6 +100,11 @@ msgstr "Campo immagine"
msgid "Images field name"
msgstr "Nome campo immagine"

#. module: search_engine_image_thumbnail
#: model:ir.model.fields,field_description:search_engine_image_thumbnail.field_se_image_field_thumbnail_size__allowed_field_ids
msgid "Images fields"
msgstr ""

#. module: search_engine_image_thumbnail
#: model:ir.model,name:search_engine_image_thumbnail.model_se_image_field_thumbnail_size
msgid "Index Thumbnail Size"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ msgstr ""
msgid "Display Name"
msgstr ""

#. module: search_engine_image_thumbnail
#: model:ir.model.fields,field_description:search_engine_image_thumbnail.field_se_image_field_thumbnail_size__field_id_domain
msgid "Domain to select images field"
msgstr ""

#. module: search_engine_image_thumbnail
#: model:ir.model.fields,field_description:search_engine_image_thumbnail.field_se_backend__fails_if_no_thumbail_size
msgid "Fail if no thumbnail size"
Expand Down Expand Up @@ -100,6 +95,11 @@ msgstr ""
msgid "Images field name"
msgstr ""

#. module: search_engine_image_thumbnail
#: model:ir.model.fields,field_description:search_engine_image_thumbnail.field_se_image_field_thumbnail_size__allowed_field_ids
msgid "Images fields"
msgstr ""

#. module: search_engine_image_thumbnail
#: model:ir.model,name:search_engine_image_thumbnail.model_se_image_field_thumbnail_size
msgid "Index Thumbnail Size"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class SeImageFieldThumbnailSize(models.Model):
"ir.model.fields",
string="Images field",
required=True,
domain="[('model_id', '=', model_id)]",
ondelete="cascade",
)
field_name = fields.Char(
Expand All @@ -44,10 +43,10 @@ class SeImageFieldThumbnailSize(models.Model):
readonly=True,
store=True,
)
field_id_domain = fields.Binary(
string="Domain to select images field",
compute="_compute_field_id_domain",
readonly=True,
allowed_field_ids = fields.Many2many(
"ir.model.fields",
string="Images fields",
compute="_compute_allowed_field_ids"
)
backend_id = fields.Many2one(
"se.backend",
Expand Down Expand Up @@ -93,26 +92,22 @@ def _is_model_valid_for_thumbnail(self, model_name):
return False

@api.depends("model_id")
def _compute_field_id_domain(self):
def _compute_allowed_field_ids(self):
for record in self:
if not record.model_id:
# Eg: NewId
record.field_id_domain = FALSE_DOMAIN
continue
domain_fields = []
if record.model_id:
model = self.env[record.model_id.model]
domain_fields = model._fields.values()

names = []
for field in domain_fields:
if self._is_field_valid_for_thumbnail(field):
names.append(field.name)
record.field_id_domain = json.dumps(
[("name", "in", names), ("model_id", "=", record.model_id.id)]
if names
else FALSE_DOMAIN
)


domain = [('name', 'in', names)]
records = self.env['ir.model.fields'].search(domain)
record.allowed_field_ids = records

Check warning on line 109 in search_engine_image_thumbnail/models/se_image_field_thumbnail_size.py

View check run for this annotation

Codecov / codecov/patch

search_engine_image_thumbnail/models/se_image_field_thumbnail_size.py#L107-L109

Added lines #L107 - L109 were not covered by tests

@api.model
def _is_field_valid_for_thumbnail(self, field: fields.Field):
if isinstance(field, fields.Image) or field.type == "fs_image":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ def test_thumbnail_size_model_domain(self):
domain = self.env["se.image.field.thumbnail.size"]._model_id_domain()
self.assertEqual(domain, expected)

def test_thumbnail_zise_field_domain(self):
model_id = self.test_multi_image_model_id
se_thumbnail_size = self.env["se.image.field.thumbnail.size"].new(
{"model_id": model_id}
)
field_id_domain = se_thumbnail_size.field_id_domain
self.assertEqual(
field_id_domain,
f'[["name", "in", ["image_ids"]], ["model_id", "=", {model_id}]]'.encode(),
)

def test_multi_image_record_create_thumbnail(self):
thumbnails = self.test_multi_image._get_or_create_thumbnails_for_multi_images(
self.index_multi_image, "image_ids"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<tree editable="top">
<field name="backend_id" invisible="context.get('hide_backend', 0)" />
<field name="model_id" />
<field name="field_id" domain="field_id_domain" />
<field name="field_id_domain" invisible="1" />
<field name="field_id" domain="[('id', 'in', allowed_field_ids), ('model_id', '=', model_id)]"/>
<field name="allowed_field_ids" widget="many2many_tags" invisible="1" />
<field name="size_ids" widget="many2many_tags" />
</tree>
</field>
Expand Down

0 comments on commit 81463a3

Please sign in to comment.