-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by lmignon
- Loading branch information
Showing
24 changed files
with
226 additions
and
137 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
1 change: 1 addition & 0 deletions
1
...arch_engine_product_brand_image/odoo/addons/shopinvader_search_engine_product_brand_image
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 @@ | ||
../../../../shopinvader_search_engine_product_brand_image |
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, | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
shopinvader_product_brand_image/models/shopinvader_backend.py
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
shopinvader_product_brand_image/models/shopinvader_brand.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
shopinvader_product_brand_image/views/shopinvader_backend_view.xml
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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 schemas |
25 changes: 25 additions & 0 deletions
25
shopinvader_search_engine_product_brand_image/__manifest__.py
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,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": [], | ||
} |
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...oduct_brand_image/readme/CONTRIBUTORS.rst → ...oduct_brand_image/readme/CONTRIBUTORS.rst
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
* Sebastien BEAU <[email protected]> | ||
* Marie LEJEUNE <[email protected]> |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
shopinvader_search_engine_product_brand_image/schemas/__init__.py
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 .brand import ProductBrand |
15 changes: 15 additions & 0 deletions
15
shopinvader_search_engine_product_brand_image/schemas/brand.py
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 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 |
File renamed without changes.
File renamed without changes.
176 changes: 176 additions & 0 deletions
176
shopinvader_search_engine_product_brand_image/tests/test_brand.py
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,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", | ||
) |