From a15302c7a6cd5d0db6e9a085dbe99f1621d20dcf Mon Sep 17 00:00:00 2001 From: David Date: Tue, 5 Nov 2024 14:00:08 +0100 Subject: [PATCH] [ADD] product_variant_template_reassign: New module TT51495 --- product_variant_template_reassign/README.rst | 103 ++++ product_variant_template_reassign/__init__.py | 1 + .../__manifest__.py | 19 + .../readme/CONTRIBUTORS.md | 3 + .../readme/DESCRIPTION.md | 1 + .../readme/ROADMAP.md | 3 + .../readme/USAGE.md | 5 + .../security/ir.model.access.csv | 2 + .../static/description/index.html | 448 ++++++++++++++++++ .../wizards/__init__.py | 1 + .../wizards/reassign_variant.py | 81 ++++ .../wizards/reassign_variant_views.xml | 39 ++ requirements.txt | 2 + .../addons/product_variant_template_reassign | 1 + .../setup.py | 6 + 15 files changed, 715 insertions(+) create mode 100644 product_variant_template_reassign/README.rst create mode 100644 product_variant_template_reassign/__init__.py create mode 100644 product_variant_template_reassign/__manifest__.py create mode 100644 product_variant_template_reassign/readme/CONTRIBUTORS.md create mode 100644 product_variant_template_reassign/readme/DESCRIPTION.md create mode 100644 product_variant_template_reassign/readme/ROADMAP.md create mode 100644 product_variant_template_reassign/readme/USAGE.md create mode 100644 product_variant_template_reassign/security/ir.model.access.csv create mode 100644 product_variant_template_reassign/static/description/index.html create mode 100644 product_variant_template_reassign/wizards/__init__.py create mode 100644 product_variant_template_reassign/wizards/reassign_variant.py create mode 100644 product_variant_template_reassign/wizards/reassign_variant_views.xml create mode 100644 requirements.txt create mode 120000 setup/product_variant_template_reassign/odoo/addons/product_variant_template_reassign create mode 100644 setup/product_variant_template_reassign/setup.py diff --git a/product_variant_template_reassign/README.rst b/product_variant_template_reassign/README.rst new file mode 100644 index 000000000..184800073 --- /dev/null +++ b/product_variant_template_reassign/README.rst @@ -0,0 +1,103 @@ +================================== +Product variant template Re-assign +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ddd8d22221dce3a8d71dc1c17660f015635e79cf6c4934c6f8fbec84fee1b183 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--variant-lightgray.png?logo=github + :target: https://github.com/OCA/product-variant/tree/15.0/product_variant_template_reassign + :alt: OCA/product-variant +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-variant-15-0/product-variant-15-0-product_variant_template_reassign + :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-variant&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Be able to assign a unique variant to a multi-variant template. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To assign variants, go to a single variant product template. + +1. In actions, choose: *Reassign variant*. +2. Choose the new product template. +3. Click on *Reassign*. + +Known issues / Roadmap +====================== + +- Filter multi-variant products only for the target template +- Filter products of the same type only for the target template +- + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__ + + - David Vidal + - Pedro M. Baeza + +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-chienandalu| image:: https://github.com/chienandalu.png?size=40px + :target: https://github.com/chienandalu + :alt: chienandalu + +Current `maintainer `__: + +|maintainer-chienandalu| + +This module is part of the `OCA/product-variant `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_variant_template_reassign/__init__.py b/product_variant_template_reassign/__init__.py new file mode 100644 index 000000000..5cb1c4914 --- /dev/null +++ b/product_variant_template_reassign/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/product_variant_template_reassign/__manifest__.py b/product_variant_template_reassign/__manifest__.py new file mode 100644 index 000000000..d5733d4e0 --- /dev/null +++ b/product_variant_template_reassign/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Product variant template Re-assign", + "summary": "Reassign variants to templates", + "version": "15.0.1.0.0", + "development_status": "Beta", + "category": "Product", + "website": "https://github.com/OCA/product-variant", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["chienandalu"], + "license": "AGPL-3", + "depends": ["product"], + "external_dependencies": {"python": ["openupgradelib"]}, + "data": [ + "security/ir.model.access.csv", + "wizards/reassign_variant_views.xml", + ], +} diff --git a/product_variant_template_reassign/readme/CONTRIBUTORS.md b/product_variant_template_reassign/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..1be173bca --- /dev/null +++ b/product_variant_template_reassign/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://tecnativa.com) + - David Vidal + - Pedro M. Baeza diff --git a/product_variant_template_reassign/readme/DESCRIPTION.md b/product_variant_template_reassign/readme/DESCRIPTION.md new file mode 100644 index 000000000..840cd59db --- /dev/null +++ b/product_variant_template_reassign/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Be able to assign a unique variant to a multi-variant template. diff --git a/product_variant_template_reassign/readme/ROADMAP.md b/product_variant_template_reassign/readme/ROADMAP.md new file mode 100644 index 000000000..ff0419738 --- /dev/null +++ b/product_variant_template_reassign/readme/ROADMAP.md @@ -0,0 +1,3 @@ +- Filter multi-variant products only for the target template +- Filter products of the same type only for the target template +- \ No newline at end of file diff --git a/product_variant_template_reassign/readme/USAGE.md b/product_variant_template_reassign/readme/USAGE.md new file mode 100644 index 000000000..b8f24f36e --- /dev/null +++ b/product_variant_template_reassign/readme/USAGE.md @@ -0,0 +1,5 @@ +To assign variants, go to a single variant product template. + +1. In actions, choose: *Reassign variant*. +2. Choose the new product template. +3. Click on *Reassign*. diff --git a/product_variant_template_reassign/security/ir.model.access.csv b/product_variant_template_reassign/security/ir.model.access.csv new file mode 100644 index 000000000..51ef5f044 --- /dev/null +++ b/product_variant_template_reassign/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +product_variant_template_reassign.access_reassign_variant,access_reassign_variant,product_variant_template_reassign.model_reassign_variant,stock.group_stock_manager,1,1,1,1 diff --git a/product_variant_template_reassign/static/description/index.html b/product_variant_template_reassign/static/description/index.html new file mode 100644 index 000000000..bc5bcab9a --- /dev/null +++ b/product_variant_template_reassign/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Product variant template Re-assign + + + +
+

Product variant template Re-assign

+ + +

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

+

Be able to assign a unique variant to a multi-variant template.

+

Table of contents

+ +
+

Usage

+

To assign variants, go to a single variant product template.

+
    +
  1. In actions, choose: Reassign variant.
  2. +
  3. Choose the new product template.
  4. +
  5. Click on Reassign.
  6. +
+
+
+

Known issues / Roadmap

+
    +
  • Filter multi-variant products only for the target template
  • +
  • Filter products of the same type only for the target template
  • +
  • +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa
      +
    • David Vidal
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

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:

+

chienandalu

+

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

+

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

+
+
+
+ + diff --git a/product_variant_template_reassign/wizards/__init__.py b/product_variant_template_reassign/wizards/__init__.py new file mode 100644 index 000000000..df7a1ea3f --- /dev/null +++ b/product_variant_template_reassign/wizards/__init__.py @@ -0,0 +1 @@ +from . import reassign_variant diff --git a/product_variant_template_reassign/wizards/reassign_variant.py b/product_variant_template_reassign/wizards/reassign_variant.py new file mode 100644 index 000000000..8c194fb87 --- /dev/null +++ b/product_variant_template_reassign/wizards/reassign_variant.py @@ -0,0 +1,81 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib.openupgrade_merge_records import merge_records + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class ReassignVariant(models.TransientModel): + _name = "reassign.variant" + _description = "Reassign variant template" + + origin_product_template_id = fields.Many2one(comodel_name="product.template") + target_product_template_id = fields.Many2one(comodel_name="product.template") + target_variant_id = fields.Many2one( + comodel_name="product.product", + domain="[('product_tmpl_id', '=', target_product_template_id)]", + ) + allowed_attribute_value_ids = fields.Many2many( + comodel_name="product.attribute.value", + compute="_compute_allowed_attribute_value_ids", + ) + attribute_value_ids = fields.Many2many( + comodel_name="product.attribute.value", + domain="[('id', 'in', allowed_attribute_value_ids)]", + ) + + @api.model + def default_get(self, fields_list): + product_template = self.env["product.template"].browse( + self.env.context.get("active_id", 0) + ) + if product_template.product_variant_count != 1: + raise UserError(_("You can only reassign unique variant products")) + res = super().default_get(fields_list) + res["origin_product_template_id"] = product_template + return res + + @api.depends("target_product_template_id") + def _compute_allowed_attribute_value_ids(self): + self.allowed_attribute_value_ids = False + for wiz in self.filtered("target_product_template_id"): + wiz.allowed_attribute_value_ids = ( + self.env["product.attribute.value"].search( + [ + ( + "attribute_id", + "in", + wiz.target_product_template_id.attribute_line_ids.attribute_id.ids, + ), + ("attribute_id.create_variant", "=", "always"), + ] + ) + - wiz.target_product_template_id.attribute_line_ids.value_ids + ) + + def reassign(self): + """No way back""" + # 1. Create variant + existing_variants = self.target_product_template_id.product_variant_ids + for attribute_value in self.attribute_value_ids: + self.target_product_template_id.attribute_value_ids.filtered( + lambda x: x.attribute_id == attribute_value.attribute_id + ).value_ids += attribute_value + new_variant = ( + self.target_product_template_id.product_variant_ids - existing_variants + ) + # 2. Merge existing variant into the new one + merge_records( + self.env, + "product.product", + self.origin_product_template_id.product_variant_id.ids, + new_variant.id, + ) + # 3. Merge origin template into the target template + merge_records( + self.env, + "product.template", + self.origin_product_template_id.ids, + self.target_product_template_id.id, + ) diff --git a/product_variant_template_reassign/wizards/reassign_variant_views.xml b/product_variant_template_reassign/wizards/reassign_variant_views.xml new file mode 100644 index 000000000..de9bd31de --- /dev/null +++ b/product_variant_template_reassign/wizards/reassign_variant_views.xml @@ -0,0 +1,39 @@ + + + + reassign.variant + +
+ + + + + + + + + +
+ +
+ +
+
+ + Reassign variant + + reassign.variant + form + new + +
diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..180fc4978 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +openupgradelib diff --git a/setup/product_variant_template_reassign/odoo/addons/product_variant_template_reassign b/setup/product_variant_template_reassign/odoo/addons/product_variant_template_reassign new file mode 120000 index 000000000..59136a85a --- /dev/null +++ b/setup/product_variant_template_reassign/odoo/addons/product_variant_template_reassign @@ -0,0 +1 @@ +../../../../product_variant_template_reassign \ No newline at end of file diff --git a/setup/product_variant_template_reassign/setup.py b/setup/product_variant_template_reassign/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/product_variant_template_reassign/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)