Skip to content

Commit

Permalink
Merge PR #1414 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
shopinvader-git-bot committed Oct 13, 2023
2 parents 6eb9cf6 + 0c659e2 commit 3771e9b
Show file tree
Hide file tree
Showing 24 changed files with 226 additions and 137 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ exclude: |
^shopinvader_pos/|
^shopinvader_price_per_qty/|
^shopinvader_product_attribute_set/|
^shopinvader_product_brand_image/|
^shopinvader_product_brand_tag/|
^shopinvader_product_manufactured_for/|
^shopinvader_product_media/|
Expand Down
6 changes: 6 additions & 0 deletions setup/shopinvader_search_engine_product_brand_image/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,
)
1 change: 0 additions & 1 deletion shopinvader_product_brand_image/__init__.py

This file was deleted.

32 changes: 0 additions & 32 deletions shopinvader_product_brand_image/__manifest__.py

This file was deleted.

12 changes: 0 additions & 12 deletions shopinvader_product_brand_image/data/ir_export_brand.xml

This file was deleted.

11 changes: 0 additions & 11 deletions shopinvader_product_brand_image/demo/backend_demo.xml

This file was deleted.

2 changes: 0 additions & 2 deletions shopinvader_product_brand_image/models/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions shopinvader_product_brand_image/models/shopinvader_backend.py

This file was deleted.

15 changes: 0 additions & 15 deletions shopinvader_product_brand_image/models/shopinvader_brand.py

This file was deleted.

26 changes: 0 additions & 26 deletions shopinvader_product_brand_image/tests/test_brand.py

This file was deleted.

21 changes: 0 additions & 21 deletions shopinvader_product_brand_image/views/shopinvader_backend_view.xml

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions shopinvader_search_engine_product_brand_image/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import schemas
25 changes: 25 additions & 0 deletions shopinvader_search_engine_product_brand_image/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2021 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


{
"name": "Shopinvader Search Engine Product Brand Image",
"summary": "Shopinvader Search Engine product Brand Image",
"version": "16.0.1.0.0",
"category": "Shopinvader",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"author": " Akretion,ACSONE SA/NV",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"shopinvader_product_brand",
"shopinvader_search_engine_image",
"shopinvader_search_engine_product_brand",
"fs_product_brand_multi_image",
],
"data": [],
"development_status": "Alpha",
"demo": [],
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Sebastien BEAU <[email protected]>
* Marie LEJEUNE <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .brand import ProductBrand
15 changes: 15 additions & 0 deletions shopinvader_search_engine_product_brand_image/schemas/brand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.shopinvader_product_brand.schemas import (
ProductBrand as BaseProductBrand,
)
from odoo.addons.shopinvader_search_engine_image.schemas import ImageMixin


class ProductBrand(BaseProductBrand, ImageMixin, extends=True):
@classmethod
def from_product_brand(cls, odoo_rec):
obj = super().from_product_brand(odoo_rec)
obj._fill_image_from_image_relation_mixin(odoo_rec, "image_ids")
return obj
176 changes: 176 additions & 0 deletions shopinvader_search_engine_product_brand_image/tests/test_brand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Copyright 2021 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64

from odoo.addons.shopinvader_search_engine_image.tests.common import (
TestSeMultiImageThumbnailCase,
)


class ProductBrandCase(TestSeMultiImageThumbnailCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.backend.image_data_url_strategy = "odoo"
# create index for brands
cls.brand_index = cls.env["se.index"].create(
{
"name": "brand",
"backend_id": cls.backend.id,
"model_id": cls.env.ref("product_brand.model_product_brand").id,
"serializer_type": "shopinvader_brand_exports",
}
)
# create sizes for brands
cls.env["se.image.field.thumbnail.size"].create(
{
"model_id": cls.env.ref("product_brand.model_product_brand").id,
"field_id": cls.env.ref(
"fs_product_brand_multi_image.field_product_brand__image_ids"
).id,
"backend_id": cls.backend.id,
"size_ids": [(6, 0, [cls.size_small.id, cls.size_medium.id])],
}
)
cls.brand = cls.env["product.brand"].create(
{
"name": "Test Brand",
}
)
cls.brand_white_image = cls.env["fs.product.brand.image"].create(
{
"sequence": 1,
"brand_id": cls.brand.id,
"specific_image": {
"filename": "white.png",
"content": base64.b64encode(cls.white_image),
},
"tag_id": cls.tag1.id,
}
)
cls.brand_black_image = cls.env["fs.product.brand.image"].create(
{
"sequence": 2,
"brand_id": cls.brand.id,
"specific_image": {
"filename": "black.png",
"content": base64.b64encode(cls.black_image),
},
"tag_id": cls.tag2.id,
}
)
cls.brand_binding = cls.brand._add_to_index(cls.brand_index)

def setUp(self):
super().setUp()
self.fs_storage = self.env["fs.storage"].create(
{
"name": "Temp FS Storage",
"protocol": "memory",
"code": "mem_dir_brand",
"directory_path": "/tmp/",
"model_xmlids": "fs_product_brand_multi_image.model_fs_product_brand_image",
"base_url": "https://media.alcyonbelux.be/",
"is_directory_path_in_url": False,
}
)

def test_basic_images_compute(self):
brand = self.brand_binding._contextualize(self.brand_binding)
data = self.brand_index.model_serializer.serialize(brand.record)
self.assertIn("images", data)
self.assertEqual(len(data["images"]), 2)

# Check the images are sorted by sequence
first_image = data["images"][0]
# we have 2 sizes as key
self.assertEqual(len(first_image), 2)
self.assertEqual(first_image.keys(), {"small", "medium"})

# check attributes of the first image
self.assertEqual(first_image["small"]["sequence"], 1)
self.assertEqual(first_image["small"]["tag"], "tag1")
self.assertEqual(first_image["small"]["alt"], self.brand.name)

self.assertRegex(
first_image["small"]["src"],
r"\/web/image\/[0-9]+\/test-brand_5_5.png",
)
self.assertRegex(
first_image["medium"]["src"],
r"\/web/image\/[0-9]+\/test-brand_10_10.png",
)
# check attributes of the second image
second_image = data["images"][1]
self.assertEqual(second_image["small"]["sequence"], 2)
self.assertEqual(second_image["small"]["tag"], "tag2")
self.assertEqual(second_image["small"]["alt"], self.brand.name)
self.assertRegex(
second_image["small"]["src"],
r"\/web/image\/[0-9]+\/test-brand_5_5.png",
)
self.assertRegex(
second_image["medium"]["src"],
r"\/web/image\/[0-9]+\/test-brand_10_10.png",
)

def test_brand_image_sequence(self):
# we change the sequence of the images
self.brand_white_image.sequence = 2
self.brand_black_image.sequence = 1
# the order into the images field should be different,
# the first image should be the black one with the tag "tag2"
self.backend.image_data_url_strategy = "odoo"
brand = self.brand_binding._contextualize(self.brand_binding)
data = self.brand_index.model_serializer.serialize(brand.record)
self.assertIn("images", data)
self.assertEqual(len(data["images"]), 2)
# Check the images are sorted by sequence
first_image = data["images"][0]
self.assertEqual(first_image["small"]["sequence"], 1)
self.assertEqual(first_image["small"]["tag"], "tag2")

second_image = data["images"][1]
self.assertEqual(second_image["small"]["sequence"], 2)
self.assertEqual(second_image["small"]["tag"], "tag1")

# change sequence again
self.brand_white_image.sequence = 1
self.brand_black_image.sequence = 2
self.brand.invalidate_recordset()
data = self.brand_index.model_serializer.serialize(brand.record)
first_image = data["images"][0]
self.assertEqual(first_image["small"]["sequence"], 1)
self.assertEqual(first_image["small"]["tag"], "tag1")

second_image = data["images"][1]
self.assertEqual(second_image["small"]["sequence"], 2)
self.assertEqual(second_image["small"]["tag"], "tag2")

def test_brand_image_src(self):
self.backend.image_data_url_strategy = "odoo"
brand = self.brand_binding._contextualize(self.brand_binding)
data = self.brand_index.model_serializer.serialize(brand.record)
image = data["images"][0]
self.assertRegex(
image["medium"]["src"],
r"\/web/image\/[0-9]+\/test-brand_10_10.png",
)

self.backend.image_data_url_strategy = "storage_url"
data = self.brand_index.model_serializer.serialize(brand.record)
image = data["images"][0]
self.assertRegex(
image["medium"]["src"],
r"https:\/\/media.alcyonbelux.be\/test-brand_10_10-[0-9]+-[0-9]+.png",
)

self.backend.image_data_url_strategy = "url_path"
data = self.brand_index.model_serializer.serialize(brand.record)
image = data["images"][0]
self.assertRegex(
image["medium"]["src"],
r"\/test-brand_10_10-[0-9]+-[0-9]+.png",
)

0 comments on commit 3771e9b

Please sign in to comment.