From da71af2bc1187b02f86cb7973a5d65135b8eb545 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Tue, 2 Apr 2024 11:01:51 +0200 Subject: [PATCH 1/2] [ADD] product_configurator_pav_price_formula --- .../README.rst | 93 ++++ .../__init__.py | 3 + .../__manifest__.py | 21 + .../models/__init__.py | 3 + .../models/product_config_session.py | 32 ++ .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + .../readme/USAGE.rst | 3 + .../static/description/index.html | 433 ++++++++++++++++++ .../tests/__init__.py | 3 + .../tests/test_product.py | 53 +++ .../product_configurator_pav_price_formula | 1 + .../setup.py | 6 + 13 files changed, 655 insertions(+) create mode 100644 product_configurator_pav_price_formula/README.rst create mode 100644 product_configurator_pav_price_formula/__init__.py create mode 100644 product_configurator_pav_price_formula/__manifest__.py create mode 100644 product_configurator_pav_price_formula/models/__init__.py create mode 100644 product_configurator_pav_price_formula/models/product_config_session.py create mode 100644 product_configurator_pav_price_formula/readme/CONTRIBUTORS.rst create mode 100644 product_configurator_pav_price_formula/readme/DESCRIPTION.rst create mode 100644 product_configurator_pav_price_formula/readme/USAGE.rst create mode 100644 product_configurator_pav_price_formula/static/description/index.html create mode 100644 product_configurator_pav_price_formula/tests/__init__.py create mode 100644 product_configurator_pav_price_formula/tests/test_product.py create mode 120000 setup/product_configurator_pav_price_formula/odoo/addons/product_configurator_pav_price_formula create mode 100644 setup/product_configurator_pav_price_formula/setup.py diff --git a/product_configurator_pav_price_formula/README.rst b/product_configurator_pav_price_formula/README.rst new file mode 100644 index 0000000000..599de1257c --- /dev/null +++ b/product_configurator_pav_price_formula/README.rst @@ -0,0 +1,93 @@ +============================================================== +Product Configurator and Product Attribute value price formula +============================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2e19f1d583cf8c0c59b7eff48a0933eaefa721080dcd56a7b510302c1e23ec4e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fproduct--configurator-lightgray.png?logo=github + :target: https://github.com/OCA/product-configurator/tree/16.0/product_configurator_pav_price_formula + :alt: OCA/product-configurator +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-configurator-16-0/product-configurator-16-0-product_configurator_pav_price_formula + :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/product-configurator&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Bridge module between product configurator and formula for product attribute values. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +A new variable is available in the attribute value's formula: + +- `config_session`: the current configuration session. + +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 +~~~~~~~ + +* Aion Tech + +Contributors +~~~~~~~~~~~~ + +* `Aion Tech `_: + + * Simone Rubino + +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. + +.. |maintainer-SirAionTech| image:: https://github.com/SirAionTech.png?size=40px + :target: https://github.com/SirAionTech + :alt: SirAionTech + +Current `maintainer `__: + +|maintainer-SirAionTech| + +This module is part of the `OCA/product-configurator `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_configurator_pav_price_formula/__init__.py b/product_configurator_pav_price_formula/__init__.py new file mode 100644 index 0000000000..b18eea3796 --- /dev/null +++ b/product_configurator_pav_price_formula/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/product_configurator_pav_price_formula/__manifest__.py b/product_configurator_pav_price_formula/__manifest__.py new file mode 100644 index 0000000000..c32da57f68 --- /dev/null +++ b/product_configurator_pav_price_formula/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Product Configurator and Product Attribute value price formula", + "version": "16.0.1.0.0", + "category": "Sales/Sales", + "summary": "Bridge module between product configurator " + "and formula for product attribute values.", + "author": "Aion Tech, Odoo Community Association (OCA)", + "maintainers": [ + "SirAionTech", + ], + "license": "AGPL-3", + "website": "https://github.com/OCA/product-configurator", + "depends": [ + "product_attribute_value_price_formula", + "product_configurator", + ], + "auto_install": True, +} diff --git a/product_configurator_pav_price_formula/models/__init__.py b/product_configurator_pav_price_formula/models/__init__.py new file mode 100644 index 0000000000..ae1264eb3b --- /dev/null +++ b/product_configurator_pav_price_formula/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import product_config_session diff --git a/product_configurator_pav_price_formula/models/product_config_session.py b/product_configurator_pav_price_formula/models/product_config_session.py new file mode 100644 index 0000000000..3794094d0d --- /dev/null +++ b/product_configurator_pav_price_formula/models/product_config_session.py @@ -0,0 +1,32 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ProductConfigSession(models.Model): + _inherit = "product.config.session" + + @api.model + def get_cfg_price(self, value_ids=None, custom_vals=None): + price = super().get_cfg_price(value_ids=value_ids, custom_vals=custom_vals) + + if value_ids is None: + value_ids = self.value_ids.ids + + product = self.product_id + product_template = self.product_tmpl_id + ptavs = self.env["product.template.attribute.value"].search( + [ + ("product_attribute_value_id", "in", value_ids), + ("product_tmpl_id", "=", product_template.id), + ] + ) + for ptav in ptavs: + formula_extra_price = ptav._eval_extra_price_formula( + product, + config_session=self, + ) + price += formula_extra_price + + return price diff --git a/product_configurator_pav_price_formula/readme/CONTRIBUTORS.rst b/product_configurator_pav_price_formula/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..6afa1541b4 --- /dev/null +++ b/product_configurator_pav_price_formula/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Aion Tech `_: + + * Simone Rubino diff --git a/product_configurator_pav_price_formula/readme/DESCRIPTION.rst b/product_configurator_pav_price_formula/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..300b97a931 --- /dev/null +++ b/product_configurator_pav_price_formula/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Bridge module between product configurator and formula for product attribute values. diff --git a/product_configurator_pav_price_formula/readme/USAGE.rst b/product_configurator_pav_price_formula/readme/USAGE.rst new file mode 100644 index 0000000000..b20310bb2b --- /dev/null +++ b/product_configurator_pav_price_formula/readme/USAGE.rst @@ -0,0 +1,3 @@ +A new variable is available in the attribute value's formula: + +- `config_session`: the current configuration session. diff --git a/product_configurator_pav_price_formula/static/description/index.html b/product_configurator_pav_price_formula/static/description/index.html new file mode 100644 index 0000000000..1bb26508ff --- /dev/null +++ b/product_configurator_pav_price_formula/static/description/index.html @@ -0,0 +1,433 @@ + + + + + +Product Configurator and Product Attribute value price formula + + + +
+

Product Configurator and Product Attribute value price formula

+ + +

Beta License: AGPL-3 OCA/product-configurator Translate me on Weblate Try me on Runboat

+

Bridge module between product configurator and formula for product attribute values.

+

Table of contents

+ +
+

Usage

+

A new variable is available in the attribute value’s formula:

+
    +
  • config_session: the current configuration session.
  • +
+
+
+

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

+
    +
  • Aion Tech
  • +
+
+
+

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.

+

Current maintainer:

+

SirAionTech

+

This module is part of the OCA/product-configurator project on GitHub.

+

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

+
+
+
+ + diff --git a/product_configurator_pav_price_formula/tests/__init__.py b/product_configurator_pav_price_formula/tests/__init__.py new file mode 100644 index 0000000000..07fe1890bb --- /dev/null +++ b/product_configurator_pav_price_formula/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_product diff --git a/product_configurator_pav_price_formula/tests/test_product.py b/product_configurator_pav_price_formula/tests/test_product.py new file mode 100644 index 0000000000..1342f3e8e3 --- /dev/null +++ b/product_configurator_pav_price_formula/tests/test_product.py @@ -0,0 +1,53 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import Form + +from odoo.addons.product_attribute_value_price_formula.tests.common import TestCommon + + +class TestCustomAttributePrice(TestCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + configurable_product_template_form = Form(cls.env["product.template"]) + configurable_product_template_form.name = "Test configurable product" + configurable_product_template_form.list_price = 0 + with configurable_product_template_form.attribute_line_ids.new() as line: + line.attribute_id = cls.attribute + line.value_ids.add(cls.attribute_value) + line.value_ids.add(cls.formula_attribute_value) + configurable_product_template = configurable_product_template_form.save() + configurable_product_template.config_ok = True + cls.configurable_product_template = configurable_product_template + + def test_configure_formula_attribute(self): + """The attribute of a configurable product has a formula, + check that it is evaluated during the configuration. + """ + # Arrange + formula_price = self.formula_price + product_template = self.product_template + formula_attribute_value = self.formula_attribute_value + formula_attribute = formula_attribute_value.attribute_id + + # Act: configure the product + wizard_action = product_template.configure_product() + wizard = self.env[wizard_action["res_model"]].browse(wizard_action["res_id"]) + self.assertEqual(wizard.state, "select") + wizard.action_next_step() + self.assertEqual(wizard.state, "configure") + fields_prefixes = wizard._prefixes + field_prefix = fields_prefixes.get("field_prefix") + wizard.write( + { + field_prefix + str(formula_attribute.id): formula_attribute_value.id, + } + ) + wizard.action_config_done() + + # Assert + configured_session = wizard.config_session_id + expected_configuration_price = product_template.list_price + formula_price + self.assertEqual(configured_session.price, expected_configuration_price) diff --git a/setup/product_configurator_pav_price_formula/odoo/addons/product_configurator_pav_price_formula b/setup/product_configurator_pav_price_formula/odoo/addons/product_configurator_pav_price_formula new file mode 120000 index 0000000000..e4ce24c0fc --- /dev/null +++ b/setup/product_configurator_pav_price_formula/odoo/addons/product_configurator_pav_price_formula @@ -0,0 +1 @@ +../../../../product_configurator_pav_price_formula \ No newline at end of file diff --git a/setup/product_configurator_pav_price_formula/setup.py b/setup/product_configurator_pav_price_formula/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/product_configurator_pav_price_formula/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 3175bdbcbfa77d6957151cc74214c0e8e789229a Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Tue, 2 Apr 2024 12:26:29 +0200 Subject: [PATCH 2/2] [DON'T MERGE] test-requirements.txt --- test-requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test-requirements.txt diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..a763a78a63 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +# https://github.com/OCA/product-attribute/pull/1531 +odoo-addon-product_attribute_value_price_formula @ git+https://github.com/OCA/product-attribute.git@refs/pull/1531/head#subdirectory=setup/product_attribute_value_price_formula