diff --git a/stock_lot_multi_image/README.rst b/stock_lot_multi_image/README.rst new file mode 100644 index 000000000000..1fdbefa1f1f7 --- /dev/null +++ b/stock_lot_multi_image/README.rst @@ -0,0 +1,105 @@ +============================ +Multiple Images in Stock Lot +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1a74bebbff3facd1bed2fe60b5f8db121b0a7679a9b07c7c2ffc33da47c52ebd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_lot_multi_image + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_lot_multi_image + :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/stock-logistics-warehouse&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to add multiple images to a stock lot. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +Sometimes it is necessary to have pictures of a specific product that is +tracked by serial numbers. + +For example you manage a stock of used laptops where each model is a +product variant and each laptop is an item with a unique serial number. +And you would like to have photos of each specific laptop, not just the +pictures of the model from the official website. + +However by default in Odoo you can add pictures only to a product +template or a product variant. + +Usage +===== + +- Go to Inventory > Products > Lots / Serial Numbers and choose a stock + lot. +- Go to the Images tab. Add a new image or edit the existing ones. +- Refresh the page. +- The first image in the collection is the main image for the stock lot. + +|Stock Lot Form View| + +.. |Stock Lot Form View| image:: https://raw.githubusercontent.com/OCA/stock-logistics-warehouse/18.0/stock_lot_multi_image/static/description/usage.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Cetmix + +Contributors +------------ + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_lot_multi_image/__init__.py b/stock_lot_multi_image/__init__.py new file mode 100644 index 000000000000..3c124c082c42 --- /dev/null +++ b/stock_lot_multi_image/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2025 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/stock_lot_multi_image/__manifest__.py b/stock_lot_multi_image/__manifest__.py new file mode 100644 index 000000000000..709c3a60f1b1 --- /dev/null +++ b/stock_lot_multi_image/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2025 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Multiple Images in Stock Lot", + "summary": """This module implements the possibility to + have multiple images for a stock lot""", + "author": "Cetmix, Odoo Community Association (OCA)", + "version": "18.0.1.0.0", + "category": "Inventory/Inventory", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "depends": [ + "stock", + "base_multi_image", + ], + "data": [ + "views/stock_lot_view.xml", + ], + "license": "AGPL-3", + "installable": True, +} diff --git a/stock_lot_multi_image/i18n/it.po b/stock_lot_multi_image/i18n/it.po new file mode 100644 index 000000000000..25e95e556533 --- /dev/null +++ b/stock_lot_multi_image/i18n/it.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_lot_multi_image +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-01-30 14:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_1024 +msgid "Image 1024" +msgstr "Immagine 1024" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_128 +msgid "Image 128" +msgstr "Immagine 128" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_1920 +msgid "Image 1920" +msgstr "Immagine 1920" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_256 +msgid "Image 256" +msgstr "Immagine 256" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_512 +msgid "Image 512" +msgstr "Immagine 512" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_ids +#: model_terms:ir.ui.view,arch_db:stock_lot_multi_image.view_production_lot_form +msgid "Images" +msgstr "Immagini" + +#. module: stock_lot_multi_image +#: model:ir.model,name:stock_lot_multi_image.model_stock_lot +msgid "Lot/Serial" +msgstr "Lotto/seriale" diff --git a/stock_lot_multi_image/i18n/stock_lot_multi_image.pot b/stock_lot_multi_image/i18n/stock_lot_multi_image.pot new file mode 100644 index 000000000000..ea457c6d84f7 --- /dev/null +++ b/stock_lot_multi_image/i18n/stock_lot_multi_image.pot @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_lot_multi_image +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_1024 +msgid "Image 1024" +msgstr "" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_128 +msgid "Image 128" +msgstr "" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_1920 +msgid "Image 1920" +msgstr "" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_256 +msgid "Image 256" +msgstr "" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_512 +msgid "Image 512" +msgstr "" + +#. module: stock_lot_multi_image +#: model:ir.model.fields,field_description:stock_lot_multi_image.field_stock_lot__image_ids +#: model_terms:ir.ui.view,arch_db:stock_lot_multi_image.view_production_lot_form +msgid "Images" +msgstr "" + +#. module: stock_lot_multi_image +#: model:ir.model,name:stock_lot_multi_image.model_stock_lot +msgid "Lot/Serial" +msgstr "" diff --git a/stock_lot_multi_image/models/__init__.py b/stock_lot_multi_image/models/__init__.py new file mode 100644 index 000000000000..f9a53bbaac30 --- /dev/null +++ b/stock_lot_multi_image/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2025 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import stock_lot diff --git a/stock_lot_multi_image/models/stock_lot.py b/stock_lot_multi_image/models/stock_lot.py new file mode 100644 index 000000000000..f0cda5e122de --- /dev/null +++ b/stock_lot_multi_image/models/stock_lot.py @@ -0,0 +1,24 @@ +# Copyright (C) 2025 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class StockLot(models.Model): + _name = "stock.lot" + _inherit = ["stock.lot", "base_multi_image.owner", "image.mixin"] + + image_1920 = fields.Binary( + compute="_compute_image_1920", + store=True, + ) + + @api.depends("image_ids") + def _compute_image_1920(self): + """ + Compute main image of lots + """ + for lot in self: + lot.image_1920 = fields.first( + lot.with_context(bin_size=False).image_ids + ).image_1920 diff --git a/stock_lot_multi_image/pyproject.toml b/stock_lot_multi_image/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/stock_lot_multi_image/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/stock_lot_multi_image/readme/CONTEXT.md b/stock_lot_multi_image/readme/CONTEXT.md new file mode 100644 index 000000000000..bf35329e7a53 --- /dev/null +++ b/stock_lot_multi_image/readme/CONTEXT.md @@ -0,0 +1,5 @@ +Sometimes it is necessary to have pictures of a specific product that is tracked by serial numbers. + +For example you manage a stock of used laptops where each model is a product variant and each laptop is an item with a unique serial number. And you would like to have photos of each specific laptop, not just the pictures of the model from the official website. + +However by default in Odoo you can add pictures only to a product template or a product variant. diff --git a/stock_lot_multi_image/readme/CONTRIBUTORS.md b/stock_lot_multi_image/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..2f6060845e2a --- /dev/null +++ b/stock_lot_multi_image/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/stock_lot_multi_image/readme/DESCRIPTION.md b/stock_lot_multi_image/readme/DESCRIPTION.md new file mode 100644 index 000000000000..2a18cfeba7b9 --- /dev/null +++ b/stock_lot_multi_image/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to add multiple images to a stock lot. diff --git a/stock_lot_multi_image/readme/USAGE.md b/stock_lot_multi_image/readme/USAGE.md new file mode 100644 index 000000000000..ed7163da1dfe --- /dev/null +++ b/stock_lot_multi_image/readme/USAGE.md @@ -0,0 +1,6 @@ +- Go to Inventory > Products > Lots / Serial Numbers and choose a stock lot. +- Go to the Images tab. Add a new image or edit the existing ones. +- Refresh the page. +- The first image in the collection is the main image for the stock lot. + +![Stock Lot Form View](../static/description/usage.png) diff --git a/stock_lot_multi_image/static/description/icon.png b/stock_lot_multi_image/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/stock_lot_multi_image/static/description/icon.png differ diff --git a/stock_lot_multi_image/static/description/index.html b/stock_lot_multi_image/static/description/index.html new file mode 100644 index 000000000000..992a546ad809 --- /dev/null +++ b/stock_lot_multi_image/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +Multiple Images in Stock Lot + + + +
+

Multiple Images in Stock Lot

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

+

This module allows to add multiple images to a stock lot.

+

Table of contents

+ +
+

Use Cases / Context

+

Sometimes it is necessary to have pictures of a specific product that is +tracked by serial numbers.

+

For example you manage a stock of used laptops where each model is a +product variant and each laptop is an item with a unique serial number. +And you would like to have photos of each specific laptop, not just the +pictures of the model from the official website.

+

However by default in Odoo you can add pictures only to a product +template or a product variant.

+
+
+

Usage

+
    +
  • Go to Inventory > Products > Lots / Serial Numbers and choose a stock +lot.
  • +
  • Go to the Images tab. Add a new image or edit the existing ones.
  • +
  • Refresh the page.
  • +
  • The first image in the collection is the main image for the stock lot.
  • +
+

Stock Lot Form View

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Cetmix
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/stock-logistics-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_lot_multi_image/static/description/usage.png b/stock_lot_multi_image/static/description/usage.png new file mode 100644 index 000000000000..e60d45fc79cd Binary files /dev/null and b/stock_lot_multi_image/static/description/usage.png differ diff --git a/stock_lot_multi_image/tests/__init__.py b/stock_lot_multi_image/tests/__init__.py new file mode 100644 index 000000000000..b0c41c99f970 --- /dev/null +++ b/stock_lot_multi_image/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_lot_multi_image diff --git a/stock_lot_multi_image/tests/test_stock_lot_multi_image.py b/stock_lot_multi_image/tests/test_stock_lot_multi_image.py new file mode 100644 index 000000000000..aa30adc22b8c --- /dev/null +++ b/stock_lot_multi_image/tests/test_stock_lot_multi_image.py @@ -0,0 +1,127 @@ +# Copyright (C) 2025 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import Command + +from odoo.addons.base.tests.common import BaseCommon + + +class TestStockLotMultiImage(BaseCommon): + @classmethod + def _get_image_vals(cls, name, image_data): + """Helper to get image values based on available fields""" + comodel = cls.env["stock.lot"]._fields["image_ids"].comodel_name + fields_list = cls.env[comodel]._fields + vals = {"name": name} + if "storage" in fields_list: + vals["storage"] = "filestore" + if "attachment_image" in fields_list: + vals["attachment_image"] = image_data + elif "image_1920" in fields_list: + vals["image_1920"] = image_data + if "owner_model" in fields_list: + vals["owner_model"] = "stock.lot" + return vals + + @classmethod + def setUpClass(cls): + super().setUpClass() + + field = cls.env["stock.lot"]._fields["image_ids"] + comodel_fields = cls.env[field.comodel_name]._fields + if "owner_model" not in comodel_fields: + field.domain = [] + + # Create test images + cls.transparent_image = ( # 1x1 Transparent GIF + b"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" + ) + cls.black_image = ( # 1x1 Black GIF + b"R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" + ) + cls.grey_image = ( # 1x1 Grey GIF + b"R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw ==" + ) + + # Create test product for lot + cls.product = cls.env["product.product"].create( + { + "name": "Test Product", + "type": "consu", + } + ) + + # Create test lot with images + cls.test_lot = cls.env["stock.lot"].create( + { + "name": "TEST/01/001", + "product_id": cls.product.id, + "company_id": cls.env.company.id, + "image_ids": [ + Command.create( + cls._get_image_vals("Image 1", cls.transparent_image) + ), + Command.create(cls._get_image_vals("Image 2", cls.black_image)), + ], + } + ) + cls.test_lot.invalidate_recordset() + + def test_compute_image_1920(self): + """Test the computation of the main image""" + self.assertTrue(self.test_lot.image_1920, "Main image should be computed") + self.assertEqual( + self.test_lot.image_1920, + self.test_lot.image_ids[0].image_1920, + "Main image should match the first image in image_ids", + ) + + def test_all_images(self): + """Test multiple images are correctly attached""" + self.assertEqual(len(self.test_lot.image_ids), 2) + + def test_add_image(self): + """Test adding a new image""" + initial_count = len(self.test_lot.image_ids) + self.test_lot.write( + { + "image_ids": [ + Command.create(self._get_image_vals("Image 3", self.grey_image)) + ] + } + ) + self.test_lot.invalidate_recordset() + self.assertEqual(len(self.test_lot.image_ids), initial_count + 1) + + def test_remove_image(self): + """Test removing an image""" + initial_images = self.test_lot.image_ids + self.assertTrue(len(initial_images) >= 2, "Test requires at least 2 images") + + # Store the second image for comparison + second_image = initial_images[1].with_context(bin_size=False).image_1920 + + # Remove the first image + self.test_lot.write({"image_ids": [Command.delete(initial_images[0].id)]}) + self.test_lot.invalidate_recordset() + + # Check the count and the new first image + self.assertEqual(len(self.test_lot.image_ids), len(initial_images) - 1) + self.assertEqual( + self.test_lot.with_context(bin_size=False).image_ids[0].image_1920, + second_image, + ) + + def test_remove_all_images(self): + """Test removing all images""" + # Remove all images using unlink + self.test_lot.write({"image_ids": [Command.clear()]}) + self.test_lot.invalidate_recordset() + self.assertEqual(len(self.test_lot.image_ids), 0) + self.assertFalse(self.test_lot.image_1920) + + def test_edit_image(self): + """Test editing image metadata""" + new_name = "Test name changed" + self.test_lot.image_ids[0].name = new_name + self.assertEqual(self.test_lot.image_ids[0].name, new_name) diff --git a/stock_lot_multi_image/views/stock_lot_view.xml b/stock_lot_multi_image/views/stock_lot_view.xml new file mode 100644 index 000000000000..22fdb6404744 --- /dev/null +++ b/stock_lot_multi_image/views/stock_lot_view.xml @@ -0,0 +1,32 @@ + + + + stock.lot.view.form + stock.lot + + + + + + + + + + + + +