diff --git a/shopinvader_optional_products/README.rst b/shopinvader_optional_products/README.rst new file mode 100644 index 0000000000..137514169b --- /dev/null +++ b/shopinvader_optional_products/README.rst @@ -0,0 +1,72 @@ +============================ +Shopinvader Optional Product +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bea320a72013088dbe13e7b885990c3ec23093811ff8beef6bf70a88205e1d2e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github + :target: https://github.com/shopinvader/odoo-shopinvader/tree/14.0/shopinvader_optional_products + :alt: shopinvader/odoo-shopinvader + +|badge1| |badge2| |badge3| + +Exports the optional products that one can define when the Sale Product Configurator module is installed. + +The optional products must be binded to the corresponding shopinvader backend. + +The JSON block exported is a list of dict that gives, for each shopinvader variant of the optional products : + + * id + * name + * description + * url_key + * images + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* `Akretion `_: + + * Olivier Nibart + +Maintainers +~~~~~~~~~~~ + +This module is part of the `shopinvader/odoo-shopinvader `_ project on GitHub. + +You are welcome to contribute. diff --git a/shopinvader_optional_products/__init__.py b/shopinvader_optional_products/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_optional_products/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_optional_products/__manifest__.py b/shopinvader_optional_products/__manifest__.py new file mode 100644 index 0000000000..d94ad7d9a7 --- /dev/null +++ b/shopinvader_optional_products/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2024 Akretion (http://www.akretion.com) +# Olivier Nibart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Shopinvader Optional Product", + "summary": "Export optional products", + "version": "14.0.0.0.1", + "category": "e-commerce", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "author": "Akretion", + "license": "AGPL-3", + "depends": [ + "shopinvader", + "sale_product_configurator", + "shopinvader_image", + "base_sparse_field", + ], + "data": [ + "data/ir_export_product.xml", + ], + "installable": True, +} diff --git a/shopinvader_optional_products/data/ir_export_product.xml b/shopinvader_optional_products/data/ir_export_product.xml new file mode 100644 index 0000000000..4d4338c827 --- /dev/null +++ b/shopinvader_optional_products/data/ir_export_product.xml @@ -0,0 +1,9 @@ + + + + + optional_products + + + + diff --git a/shopinvader_optional_products/models/__init__.py b/shopinvader_optional_products/models/__init__.py new file mode 100644 index 0000000000..6a236b64ff --- /dev/null +++ b/shopinvader_optional_products/models/__init__.py @@ -0,0 +1 @@ +from . import shopinvader_variant diff --git a/shopinvader_optional_products/models/shopinvader_variant.py b/shopinvader_optional_products/models/shopinvader_variant.py new file mode 100644 index 0000000000..a645f7bbde --- /dev/null +++ b/shopinvader_optional_products/models/shopinvader_variant.py @@ -0,0 +1,33 @@ +# Copyright 2024 Akretion (http://www.akretion.com) +# Olivier Nibart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ShopinvaderVariant(models.Model): + _inherit = "shopinvader.variant" + + optional_products = fields.Serialized( + compute="_compute_optional_products", string="Shopinvader Optional Products" + ) + + def _compute_optional_products(self): + for record in self: + optional_products = [] + for pt in record.optional_product_ids: + variants = pt.shopinvader_bind_ids.filtered( + lambda x, rec=record: x.backend_id == rec.backend_id + and x.lang_id == rec.lang_id + ).shopinvader_variant_ids + for variant in variants: + optional_products.append( + { + "name": variant.name, + "id": variant.id, + "description": variant.description or "", + "url_key": variant.url_key, + "images": variant.images, + } + ) + record.optional_products = optional_products diff --git a/shopinvader_optional_products/readme/CONTRIBUTORS.rst b/shopinvader_optional_products/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..d2313b6b9b --- /dev/null +++ b/shopinvader_optional_products/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Akretion `_: + + * Olivier Nibart diff --git a/shopinvader_optional_products/readme/DESCRIPTION.rst b/shopinvader_optional_products/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..d5055fa9b2 --- /dev/null +++ b/shopinvader_optional_products/readme/DESCRIPTION.rst @@ -0,0 +1,11 @@ +Exports the optional products that one can define when the Sale Product Configurator module is installed. + +The optional products must be binded to the corresponding shopinvader backend. + +The JSON block exported is a list of dict that gives, for each shopinvader variant of the optional products : + + * id + * name + * description + * url_key + * images diff --git a/shopinvader_optional_products/static/description/index.html b/shopinvader_optional_products/static/description/index.html new file mode 100644 index 0000000000..b8728dc70f --- /dev/null +++ b/shopinvader_optional_products/static/description/index.html @@ -0,0 +1,429 @@ + + + + + +Shopinvader Optional Product + + + +
+

Shopinvader Optional Product

+ + +

Beta License: AGPL-3 shopinvader/odoo-shopinvader

+

Exports the optional products that one can define when the Sale Product Configurator module is installed.

+

The optional products must be binded to the corresponding shopinvader backend.

+

The JSON block exported is a list of dict that gives, for each shopinvader variant of the optional products :

+
+
    +
  • id
  • +
  • name
  • +
  • description
  • +
  • url_key
  • +
  • images
  • +
+
+

Table of contents

+ +
+

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

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the shopinvader/odoo-shopinvader project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/shopinvader_optional_products/tests/__init__.py b/shopinvader_optional_products/tests/__init__.py new file mode 100644 index 0000000000..35ee3189f5 --- /dev/null +++ b/shopinvader_optional_products/tests/__init__.py @@ -0,0 +1 @@ +from . import test_shopinvader_optional_products diff --git a/shopinvader_optional_products/tests/test_shopinvader_optional_products.py b/shopinvader_optional_products/tests/test_shopinvader_optional_products.py new file mode 100644 index 0000000000..ca0aba18c8 --- /dev/null +++ b/shopinvader_optional_products/tests/test_shopinvader_optional_products.py @@ -0,0 +1,53 @@ +# Copyright 2024 Akretion (http://www.akretion.com) +# Olivier Nibart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import SavepointCase + +from odoo.addons.shopinvader.tests.common import _install_lang_odoo + + +class ShopinvaderOptionalProducts(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # time saver + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + lang = _install_lang_odoo(cls.env, "base.lang_fr") + cls.backend = cls.env.ref("shopinvader.backend_1") + cls.backend.lang_ids |= lang + cls.backend.bind_all_product() + + def test_compute_optional_products(self): + customizable_product_id = self.env.ref( + "product.product_product_13_product_template" + ) + optional_product_ids = customizable_product_id.optional_product_ids + optional_product_ids.optional_product_ids = [(5, 0, 0)] + optional_variant_ids = optional_product_ids.product_variant_ids + for ( + shopinvader_variant_id + ) in customizable_product_id.shopinvader_bind_ids.shopinvader_variant_ids: + optional_products = shopinvader_variant_id.optional_products + self.assertEqual(len(optional_products), len(optional_variant_ids)) + shopinvader_options_variant_ids = self.env["shopinvader.variant"].browse( + [x["id"] for x in optional_products] + ) + self.assertTrue( + all( + [ + x.backend_id == shopinvader_variant_id.backend_id + for x in shopinvader_options_variant_ids + ] + ) + ) + self.assertTrue( + all( + [ + x.lang_id == shopinvader_variant_id.lang_id + for x in shopinvader_options_variant_ids + ] + ) + ) + for shopinvader_options_variant_id in shopinvader_options_variant_ids: + self.assertEqual([], shopinvader_options_variant_id.optional_products)