From b33336473652bf580dcfc3d9462a5a2f181314a5 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 | 98 ++++ product_variant_template_reassign/__init__.py | 1 + .../__manifest__.py | 19 + product_variant_template_reassign/i18n/es.po | 155 ++++++ .../product_variant_template_reassign.pot | 143 ++++++ .../readme/CONTRIBUTORS.md | 3 + .../readme/DESCRIPTION.md | 1 + .../readme/USAGE.md | 7 + .../security/ir.model.access.csv | 2 + .../static/description/index.html | 441 ++++++++++++++++++ .../tests/__init__.py | 0 .../tests/test_product_variant_reassign.py | 10 + .../wizards/__init__.py | 1 + .../wizards/reassign_variant.py | 131 ++++++ .../wizards/reassign_variant_views.xml | 66 +++ requirements.txt | 2 + .../addons/product_variant_template_reassign | 1 + .../setup.py | 6 + 18 files changed, 1087 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/i18n/es.po create mode 100644 product_variant_template_reassign/i18n/product_variant_template_reassign.pot 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/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/tests/__init__.py create mode 100644 product_variant_template_reassign/tests/test_product_variant_reassign.py 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..738bbdb17 --- /dev/null +++ b/product_variant_template_reassign/README.rst @@ -0,0 +1,98 @@ +================================= +Product variant template reassign +================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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 target product template. +3. Choose the variant attributes if available (otherwise you won't be + able to reassign the variant) +4. Click on *Reassign*. + +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..7c6754448 --- /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 reassign", + "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/i18n/es.po b/product_variant_template_reassign/i18n/es.po new file mode 100644 index 000000000..8cfe31aea --- /dev/null +++ b/product_variant_template_reassign/i18n/es.po @@ -0,0 +1,155 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_variant_template_reassign +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-11-05 15:16+0000\n" +"PO-Revision-Date: 2024-11-05 16:22+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.4.4\n" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "" +" No attributes available for " +"create a new variant in the target template" +msgstr "" +" No hay atributos disponibles para " +"crear una nueva variante en la plantilla de destino" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "" +" Reassigning this template variant " +"to the selected target can't be undone" +msgstr "" +" Reasignar la variante de esta " +"plantilla al objetivo seleccionado no se puede deshacer" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__allowed_attribute_value_ids +msgid "Allowed Attribute Value" +msgstr "Valor de atributo permitido" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__allowed_target_product_template_ids +msgid "Allowed Target Product Template" +msgstr "Plantilla de producto destino permitida" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__attribute_value_ids +msgid "Attribute Value" +msgstr "Valor de atributo" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "Cancel" +msgstr "Cancelar" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__create_date +msgid "Created on" +msgstr "Creado el" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__id +msgid "ID" +msgstr "ID (identificación)" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant____last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__write_uid +msgid "Last Updated by" +msgstr "Última actualización de" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__write_date +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__origin_product_template_id +msgid "Origin Product Template" +msgstr "Plantilla de producto de origen" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "Reassign" +msgstr "Reasignar" + +#. module: product_variant_template_reassign +#: model:ir.actions.act_window,name:product_variant_template_reassign.reassign_variant_action +msgid "Reassign variant" +msgstr "Reasignar variante" + +#. module: product_variant_template_reassign +#: model:ir.model,name:product_variant_template_reassign.model_reassign_variant +msgid "Reassign variant template" +msgstr "Reasignar plantilla de producto" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "Select the target template" +msgstr "Seleccionar la plantilla de destino" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__target_product_template_id +msgid "Target Product Template" +msgstr "Plantilla de producto de destino" + +#. module: product_variant_template_reassign +#: code:addons/product_variant_template_reassign/wizards/reassign_variant.py:0 +#, python-format +msgid "" +"The attributes selected didn't generate a variant in the target template" +msgstr "" +"Los atributos seleccionados no han generado una variante en la plantilla de " +"destino" + +#. module: product_variant_template_reassign +#: code:addons/product_variant_template_reassign/wizards/reassign_variant.py:0 +#, python-format +msgid "" +"The attributes selected generate more than one variant. Refine your " +"configuration" +msgstr "" +"Los atributos seleccionados han generado más de una variante. Refinar los " +"parámetros" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "" +"This will merge the current template into the selected one and it can't be " +"undone" +msgstr "" +"Estos fusionará la plantilla de origen en la plantilla destino y esto no se " +"puede deshacer" + +#. module: product_variant_template_reassign +#: code:addons/product_variant_template_reassign/wizards/reassign_variant.py:0 +#, python-format +msgid "You can only reassign unique variant products" +msgstr "Solo se pueden reasignar plantillas con variante única" diff --git a/product_variant_template_reassign/i18n/product_variant_template_reassign.pot b/product_variant_template_reassign/i18n/product_variant_template_reassign.pot new file mode 100644 index 000000000..a5404e215 --- /dev/null +++ b/product_variant_template_reassign/i18n/product_variant_template_reassign.pot @@ -0,0 +1,143 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_variant_template_reassign +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-11-05 15:15+0000\n" +"PO-Revision-Date: 2024-11-05 15:15+0000\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: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "" +" No attributes available for create" +" a new variant in the target template" +msgstr "" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "" +" Reassigning this template variant " +"to the selected target can't be undone" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__allowed_attribute_value_ids +msgid "Allowed Attribute Value" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__allowed_target_product_template_ids +msgid "Allowed Target Product Template" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__attribute_value_ids +msgid "Attribute Value" +msgstr "" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "Cancel" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__create_uid +msgid "Created by" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__create_date +msgid "Created on" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__display_name +msgid "Display Name" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__id +msgid "ID" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant____last_update +msgid "Last Modified on" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__write_date +msgid "Last Updated on" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__origin_product_template_id +msgid "Origin Product Template" +msgstr "" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "Reassign" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.actions.act_window,name:product_variant_template_reassign.reassign_variant_action +msgid "Reassign variant" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model,name:product_variant_template_reassign.model_reassign_variant +msgid "Reassign variant template" +msgstr "" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "Select the target template" +msgstr "" + +#. module: product_variant_template_reassign +#: model:ir.model.fields,field_description:product_variant_template_reassign.field_reassign_variant__target_product_template_id +msgid "Target Product Template" +msgstr "" + +#. module: product_variant_template_reassign +#: code:addons/product_variant_template_reassign/wizards/reassign_variant.py:0 +#, python-format +msgid "" +"The attributes selected didn't generate a variant in the target template" +msgstr "" + +#. module: product_variant_template_reassign +#: code:addons/product_variant_template_reassign/wizards/reassign_variant.py:0 +#, python-format +msgid "" +"The attributes selected generate more than one variant. Refine your " +"configuration" +msgstr "" + +#. module: product_variant_template_reassign +#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form +msgid "" +"This will merge the current template into the selected one and it can't be " +"undone" +msgstr "" + +#. module: product_variant_template_reassign +#: code:addons/product_variant_template_reassign/wizards/reassign_variant.py:0 +#, python-format +msgid "You can only reassign unique variant products" +msgstr "" 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/USAGE.md b/product_variant_template_reassign/readme/USAGE.md new file mode 100644 index 000000000..a4eca5715 --- /dev/null +++ b/product_variant_template_reassign/readme/USAGE.md @@ -0,0 +1,7 @@ +To assign variants, go to a single variant product template. + +1. In actions, choose: *Reassign variant*. +2. Choose the target product template. +3. Choose the variant attributes if available (otherwise you won't be able to reassign + the variant) +4. 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..e122b90a7 --- /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,base.group_user,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..f31a3d580 --- /dev/null +++ b/product_variant_template_reassign/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +Product variant template reassign + + + +
+

Product variant template reassign

+ + +

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 target product template.
  4. +
  5. Choose the variant attributes if available (otherwise you won’t be +able to reassign the variant)
  6. +
  7. Click on Reassign.
  8. +
+
+
+

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/tests/__init__.py b/product_variant_template_reassign/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/product_variant_template_reassign/tests/test_product_variant_reassign.py b/product_variant_template_reassign/tests/test_product_variant_reassign.py new file mode 100644 index 000000000..ff30209e7 --- /dev/null +++ b/product_variant_template_reassign/tests/test_product_variant_reassign.py @@ -0,0 +1,10 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests.common import TransactionCase + + +class ProductVariantReassignCase(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # 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..9e0a08433 --- /dev/null +++ b/product_variant_template_reassign/wizards/reassign_variant.py @@ -0,0 +1,131 @@ +# 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") + allowed_target_product_template_ids = fields.Many2many( + comodel_name="product.template", + compute="_compute_allowed_target_product_template_ids", + ) + target_product_template_id = fields.Many2one( + comodel_name="product.template", + domain="[('id', 'in', allowed_target_product_template_ids)]", + ) + 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)]", + compute="_compute_attribute_value_ids", + readonly=False, + store=True, + ) + + @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("origin_product_template_id") + def _compute_allowed_target_product_template_ids(self): + self.allowed_target_product_template_ids = False + for wiz in self.filtered("origin_product_template_id"): + wiz.allowed_target_product_template_ids = self.env[ + "product.template" + ].search( + [ + ("type", "=", wiz.origin_product_template_id.type), + ("id", "!=", wiz.origin_product_template_id.id), + ("attribute_line_ids", "!=", False), + ] + ) + + @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 + ) + + @api.depends("target_product_template_id") + def _compute_attribute_value_ids(self): + """Whenever the target changes we must wipe the attribute values""" + self.attribute_value_ids = False + + def reassign(self): + """No way back! The potential new variant from the selected attributes is + merged with the origin variant""" + # 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_line_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 + ) + if not new_variant: + raise UserError( + _( + "The attributes selected didn't generate a variant in the target template" + ) + ) + try: + new_variant.ensure_one() + except ValueError: + raise UserError( + _( + "The attributes selected generate more than one variant. " + "Refine your configuration" + ) + ) from None + # 2. Merge existing variant into the new one. Do it with SQL to avoid ORM locks + merge_records( + self.env, + "product.product", + self.origin_product_template_id.product_variant_id.ids, + new_variant.id, + method="sql", + ) + # 3. Merge origin template into the target template. Do it with SQL to avoid ORM + # locks. + merge_records( + self.env, + "product.template", + self.origin_product_template_id.ids, + self.target_product_template_id.id, + method="sql", + ) + return { + "type": "ir.actions.act_window", + "res_model": "product.template", + "view_type": "form", + "res_id": 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..199fd0624 --- /dev/null +++ b/product_variant_template_reassign/wizards/reassign_variant_views.xml @@ -0,0 +1,66 @@ + + + + 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, +)