From c251982bdbee7ebca71fb3d499fc668fb05b6f69 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Mon, 15 Sep 2025 15:21:27 +0200 Subject: [PATCH] [IMP] apps_product_creator: Update module version When the link between the variant and the odoo module at a specific version is lost (i.e. product.product.odoo_module_version_id is empty), the odoo.module._update_product() should be able to restore it. --- apps_product_creator/README.rst | 10 ++-- apps_product_creator/models/odoo_module.py | 14 ++++++ apps_product_creator/readme/CONTRIBUTORS.rst | 4 ++ .../static/description/index.html | 48 +++++++++---------- .../tests/test_apps_product_creator.py | 19 ++++++++ 5 files changed, 65 insertions(+), 30 deletions(-) diff --git a/apps_product_creator/README.rst b/apps_product_creator/README.rst index 4ee08a8a..f7a977ad 100644 --- a/apps_product_creator/README.rst +++ b/apps_product_creator/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ====================== Github product creator ====================== @@ -17,7 +13,7 @@ Github product creator .. |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/license-AGPL--3-blue.png +.. |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%2Fapps--store-lightgray.png?logo=github @@ -127,6 +123,10 @@ Contributors * Alexandre D. Díaz * Ernesto Tejeda +* `PyTech `_: + + * Simone Rubino + Other credits ~~~~~~~~~~~~~ diff --git a/apps_product_creator/models/odoo_module.py b/apps_product_creator/models/odoo_module.py index ab5ba38d..59c8b406 100644 --- a/apps_product_creator/models/odoo_module.py +++ b/apps_product_creator/models/odoo_module.py @@ -94,6 +94,20 @@ def _update_product(self): product._create_variant_ids() product.active = True product.website_published = True + no_version_variants = product.product_variant_ids.filtered( + lambda variant: not variant.odoo_module_version_id + ) + for variant in no_version_variants: + values = ( + variant.product_template_attribute_value_ids.product_attribute_value_id + ) + for value in values: + version = self.env["product.product"]._get_version_with_attribute( + module.module_version_ids, value + ) + if version: + variant.odoo_module_version_id = version + break @api.model def _update_series_product_attribute_values(self): diff --git a/apps_product_creator/readme/CONTRIBUTORS.rst b/apps_product_creator/readme/CONTRIBUTORS.rst index bda242ca..c64b2b42 100644 --- a/apps_product_creator/readme/CONTRIBUTORS.rst +++ b/apps_product_creator/readme/CONTRIBUTORS.rst @@ -12,3 +12,7 @@ * Carlos Roca * Alexandre D. Díaz * Ernesto Tejeda + +* `PyTech `_: + + * Simone Rubino diff --git a/apps_product_creator/static/description/index.html b/apps_product_creator/static/description/index.html index e13814a1..0cfa0e3f 100644 --- a/apps_product_creator/static/description/index.html +++ b/apps_product_creator/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Github product creator -
+
+

Github product creator

- - -Odoo Community Association - -
-

Github product creator

-

Beta License: AGPL-3 OCA/apps-store Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/apps-store Translate me on Weblate Try me on Runboat

This module extends the functionality of the module Github connector to create a product for every module found. A variant is also created for every version of the module.

Table of contents

@@ -404,7 +399,7 @@

Github product creator

-

Configuration

+

Configuration

There’s an scheduled action that creates the product, disabled by default. For enabling it:

  1. Go to Settings > Technical > Automation > Scheduled Actions.
  2. @@ -412,7 +407,7 @@

    Configuration

-

Usage

+

Usage

To see the module working

    @@ -429,33 +424,33 @@

    Usage

    Now you can see the products created.
-

Changelog

+

Changelog

-

11.0.1.1.2 (2018-10-02)

+

11.0.1.1.2 (2018-10-02)

  • Publish the modules automatically on the website
-

11.0.1.1.0 (2018-10-02)

+

11.0.1.1.0 (2018-10-02)

-

Bug Tracker

+

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 @@ -471,15 +466,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • BizzAppDev
-

Contributors

+

Contributors

+
  • PyTech: +
  • -

    Other credits

    +

    Other credits

    -

    Images

    +

    Images

    • Odoo Community Association: Icon.
    -

    Maintainers

    +

    Maintainers

    This module is maintained by the OCA.

    Odoo Community Association @@ -520,6 +519,5 @@

    Maintainers

    -
    diff --git a/apps_product_creator/tests/test_apps_product_creator.py b/apps_product_creator/tests/test_apps_product_creator.py index e24fb20a..97b8fa65 100644 --- a/apps_product_creator/tests/test_apps_product_creator.py +++ b/apps_product_creator/tests/test_apps_product_creator.py @@ -107,3 +107,22 @@ def test_odoo_module_update_product(self): self.odoo_module2._update_product() self.assertTrue(self.odoo_module2.product_template_id.active) self.assertTrue(self.odoo_module2.product_template_id.website_published) + + def test_restore_variant_module_version(self): + # Arrange + module = self.odoo_module2 + module.action_create_product() + template = module.product_template_id + variant = template.product_variant_ids + module_version = variant.odoo_module_version_id + variant.odoo_module_version_id = False + # pre-condition + self.assertEqual(len(variant), 1) + self.assertFalse(variant.odoo_module_version_id) + self.assertTrue(module_version) + + # Act + module._update_product() + + # Assert + self.assertEqual(variant.odoo_module_version_id, module_version)