From 6b88490f231fffe82ccff8d936eacfac9c38c754 Mon Sep 17 00:00:00 2001
From: David <david.vidal@tecnativa.com>
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  | 176 +++++++
 .../product_variant_template_reassign.pot     | 163 +++++++
 .../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                         |   1 +
 .../tests/test_product_variant_reassign.py    |  62 +++
 .../wizards/__init__.py                       |   1 +
 .../wizards/reassign_variant.py               | 151 ++++++
 .../wizards/reassign_variant_views.xml        |  70 +++
 requirements.txt                              |   2 +
 .../addons/product_variant_template_reassign  |   1 +
 .../setup.py                                  |   6 +
 18 files changed, 1205 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 <https://github.com/OCA/product-variant/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 <https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_template_reassign%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
+
+Do not contact contributors directly about support or help with technical issues.
+
+Credits
+=======
+
+Authors
+-------
+
+* Tecnativa
+
+Contributors
+------------
+
+-  `Tecnativa <https://tecnativa.com>`__
+
+   -  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 <https://odoo-community.org/page/maintainer-role>`__:
+
+|maintainer-chienandalu| 
+
+This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/15.0/product_variant_template_reassign>`_ 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..02f16dbd3
--- /dev/null
+++ b/product_variant_template_reassign/i18n/es.po
@@ -0,0 +1,176 @@
+# 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 17:35+0000\n"
+"PO-Revision-Date: 2024-11-05 18:38+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 ""
+"<i class=\"fa fa-exclamation-triangle\"/> No attributes available for "
+"create a new variant in the target template"
+msgstr ""
+"<i class=\"fa fa-exclamation-triangle\"/> 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 ""
+"<i class=\"fa fa-exclamation-triangle\"/> Reassigning this template variant "
+"to the selected target\n"
+"                        <strong>can't be undone</strong>"
+msgstr ""
+"<i class=\"fa fa-exclamation-triangle\"/> Reasignar la variante de esta "
+"plantilla al objetivo seleccionado <strong>no se puede deshacer</strong>"
+
+#. 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__method
+msgid "Method"
+msgstr "Método"
+
+#. module: product_variant_template_reassign
+#: model:ir.model.fields.selection,name:product_variant_template_reassign.selection__reassign_variant__method__orm
+msgid "ORM - Try to respect Odoo's data flows"
+msgstr "ORM - Intentar respetar los flujos de datos de Odoo"
+
+#. 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:ir.model.fields.selection,name:product_variant_template_reassign.selection__reassign_variant__method__sql
+msgid "SQL - When the first on fails"
+msgstr "SQL - Cuando anterior falla"
+
+#. 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 selected attributes 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 selected attributes generate more than one variant. Refine your "
+"configuration"
+msgstr ""
+"Los atributos seleccionados generan más de una variante. Refine su "
+"configuración"
+
+#. 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
+#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form
+msgid "Variant to move"
+msgstr "Variante a mover"
+
+#. 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..7221f547c
--- /dev/null
+++ b/product_variant_template_reassign/i18n/product_variant_template_reassign.pot
@@ -0,0 +1,163 @@
+# 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 17:35+0000\n"
+"PO-Revision-Date: 2024-11-05 17:35+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 ""
+"<i class=\"fa fa-exclamation-triangle\"/> 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 ""
+"<i class=\"fa fa-exclamation-triangle\"/> Reassigning this template variant to the selected target\n"
+"                        <strong>can't be undone</strong>"
+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__method
+msgid "Method"
+msgstr ""
+
+#. module: product_variant_template_reassign
+#: model:ir.model.fields.selection,name:product_variant_template_reassign.selection__reassign_variant__method__orm
+msgid "ORM - Try to respect Odoo's data flows"
+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:ir.model.fields.selection,name:product_variant_template_reassign.selection__reassign_variant__method__sql
+msgid "SQL - When the first on fails"
+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 selected attributes 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 selected attributes 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
+#: model_terms:ir.ui.view,arch_db:product_variant_template_reassign.reassign_variant_form
+msgid "Variant to move"
+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 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
+<title>Product variant template reassign</title>
+<style type="text/css">
+
+/*
+:Author: David Goodger (goodger@python.org)
+:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
+:Copyright: This stylesheet has been placed in the public domain.
+
+Default cascading style sheet for the HTML output of Docutils.
+Despite the name, some widely supported CSS2 features are used.
+
+See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
+customize this style sheet.
+*/
+
+/* used to remove borders from tables and images */
+.borderless, table.borderless td, table.borderless th {
+  border: 0 }
+
+table.borderless td, table.borderless th {
+  /* Override padding for "table.docutils td" with "! important".
+     The right padding separates the table cells. */
+  padding: 0 0.5em 0 0 ! important }
+
+.first {
+  /* Override more specific margin styles with "! important". */
+  margin-top: 0 ! important }
+
+.last, .with-subtitle {
+  margin-bottom: 0 ! important }
+
+.hidden {
+  display: none }
+
+.subscript {
+  vertical-align: sub;
+  font-size: smaller }
+
+.superscript {
+  vertical-align: super;
+  font-size: smaller }
+
+a.toc-backref {
+  text-decoration: none ;
+  color: black }
+
+blockquote.epigraph {
+  margin: 2em 5em ; }
+
+dl.docutils dd {
+  margin-bottom: 0.5em }
+
+object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
+  overflow: hidden;
+}
+
+/* Uncomment (and remove this text!) to get bold-faced definition list terms
+dl.docutils dt {
+  font-weight: bold }
+*/
+
+div.abstract {
+  margin: 2em 5em }
+
+div.abstract p.topic-title {
+  font-weight: bold ;
+  text-align: center }
+
+div.admonition, div.attention, div.caution, div.danger, div.error,
+div.hint, div.important, div.note, div.tip, div.warning {
+  margin: 2em ;
+  border: medium outset ;
+  padding: 1em }
+
+div.admonition p.admonition-title, div.hint p.admonition-title,
+div.important p.admonition-title, div.note p.admonition-title,
+div.tip p.admonition-title {
+  font-weight: bold ;
+  font-family: sans-serif }
+
+div.attention p.admonition-title, div.caution p.admonition-title,
+div.danger p.admonition-title, div.error p.admonition-title,
+div.warning p.admonition-title, .code .error {
+  color: red ;
+  font-weight: bold ;
+  font-family: sans-serif }
+
+/* Uncomment (and remove this text!) to get reduced vertical space in
+   compound paragraphs.
+div.compound .compound-first, div.compound .compound-middle {
+  margin-bottom: 0.5em }
+
+div.compound .compound-last, div.compound .compound-middle {
+  margin-top: 0.5em }
+*/
+
+div.dedication {
+  margin: 2em 5em ;
+  text-align: center ;
+  font-style: italic }
+
+div.dedication p.topic-title {
+  font-weight: bold ;
+  font-style: normal }
+
+div.figure {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+div.footer, div.header {
+  clear: both;
+  font-size: smaller }
+
+div.line-block {
+  display: block ;
+  margin-top: 1em ;
+  margin-bottom: 1em }
+
+div.line-block div.line-block {
+  margin-top: 0 ;
+  margin-bottom: 0 ;
+  margin-left: 1.5em }
+
+div.sidebar {
+  margin: 0 0 0.5em 1em ;
+  border: medium outset ;
+  padding: 1em ;
+  background-color: #ffffee ;
+  width: 40% ;
+  float: right ;
+  clear: right }
+
+div.sidebar p.rubric {
+  font-family: sans-serif ;
+  font-size: medium }
+
+div.system-messages {
+  margin: 5em }
+
+div.system-messages h1 {
+  color: red }
+
+div.system-message {
+  border: medium outset ;
+  padding: 1em }
+
+div.system-message p.system-message-title {
+  color: red ;
+  font-weight: bold }
+
+div.topic {
+  margin: 2em }
+
+h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
+h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
+  margin-top: 0.4em }
+
+h1.title {
+  text-align: center }
+
+h2.subtitle {
+  text-align: center }
+
+hr.docutils {
+  width: 75% }
+
+img.align-left, .figure.align-left, object.align-left, table.align-left {
+  clear: left ;
+  float: left ;
+  margin-right: 1em }
+
+img.align-right, .figure.align-right, object.align-right, table.align-right {
+  clear: right ;
+  float: right ;
+  margin-left: 1em }
+
+img.align-center, .figure.align-center, object.align-center {
+  display: block;
+  margin-left: auto;
+  margin-right: auto;
+}
+
+table.align-center {
+  margin-left: auto;
+  margin-right: auto;
+}
+
+.align-left {
+  text-align: left }
+
+.align-center {
+  clear: both ;
+  text-align: center }
+
+.align-right {
+  text-align: right }
+
+/* reset inner alignment in figures */
+div.align-right {
+  text-align: inherit }
+
+/* div.align-center * { */
+/*   text-align: left } */
+
+.align-top    {
+  vertical-align: top }
+
+.align-middle {
+  vertical-align: middle }
+
+.align-bottom {
+  vertical-align: bottom }
+
+ol.simple, ul.simple {
+  margin-bottom: 1em }
+
+ol.arabic {
+  list-style: decimal }
+
+ol.loweralpha {
+  list-style: lower-alpha }
+
+ol.upperalpha {
+  list-style: upper-alpha }
+
+ol.lowerroman {
+  list-style: lower-roman }
+
+ol.upperroman {
+  list-style: upper-roman }
+
+p.attribution {
+  text-align: right ;
+  margin-left: 50% }
+
+p.caption {
+  font-style: italic }
+
+p.credits {
+  font-style: italic ;
+  font-size: smaller }
+
+p.label {
+  white-space: nowrap }
+
+p.rubric {
+  font-weight: bold ;
+  font-size: larger ;
+  color: maroon ;
+  text-align: center }
+
+p.sidebar-title {
+  font-family: sans-serif ;
+  font-weight: bold ;
+  font-size: larger }
+
+p.sidebar-subtitle {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+p.topic-title {
+  font-weight: bold }
+
+pre.address {
+  margin-bottom: 0 ;
+  margin-top: 0 ;
+  font: inherit }
+
+pre.literal-block, pre.doctest-block, pre.math, pre.code {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+pre.code .ln { color: gray; } /* line numbers */
+pre.code, code { background-color: #eeeeee }
+pre.code .comment, code .comment { color: #5C6576 }
+pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
+pre.code .literal.string, code .literal.string { color: #0C5404 }
+pre.code .name.builtin, code .name.builtin { color: #352B84 }
+pre.code .deleted, code .deleted { background-color: #DEB0A1}
+pre.code .inserted, code .inserted { background-color: #A3D289}
+
+span.classifier {
+  font-family: sans-serif ;
+  font-style: oblique }
+
+span.classifier-delimiter {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+span.interpreted {
+  font-family: sans-serif }
+
+span.option {
+  white-space: nowrap }
+
+span.pre {
+  white-space: pre }
+
+span.problematic, pre.problematic {
+  color: red }
+
+span.section-subtitle {
+  /* font-size relative to parent (h1..h6 element) */
+  font-size: 80% }
+
+table.citation {
+  border-left: solid 1px gray;
+  margin-left: 1px }
+
+table.docinfo {
+  margin: 2em 4em }
+
+table.docutils {
+  margin-top: 0.5em ;
+  margin-bottom: 0.5em }
+
+table.footnote {
+  border-left: solid 1px black;
+  margin-left: 1px }
+
+table.docutils td, table.docutils th,
+table.docinfo td, table.docinfo th {
+  padding-left: 0.5em ;
+  padding-right: 0.5em ;
+  vertical-align: top }
+
+table.docutils th.field-name, table.docinfo th.docinfo-name {
+  font-weight: bold ;
+  text-align: left ;
+  white-space: nowrap ;
+  padding-left: 0 }
+
+/* "booktabs" style (no vertical lines) */
+table.docutils.booktabs {
+  border: 0px;
+  border-top: 2px solid;
+  border-bottom: 2px solid;
+  border-collapse: collapse;
+}
+table.docutils.booktabs * {
+  border: 0px;
+}
+table.docutils.booktabs th {
+  border-bottom: thin solid;
+  text-align: left;
+}
+
+h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
+h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
+  font-size: 100% }
+
+ul.auto-toc {
+  list-style-type: none }
+
+</style>
+</head>
+<body>
+<div class="document" id="product-variant-template-reassign">
+<h1 class="title">Product variant template reassign</h1>
+
+<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! This file is generated by oca-gen-addon-readme !!
+!! changes will be overwritten.                   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! source digest: sha256:ddd8d22221dce3a8d71dc1c17660f015635e79cf6c4934c6f8fbec84fee1b183
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
+<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-variant/tree/15.0/product_variant_template_reassign"><img alt="OCA/product-variant" src="https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-variant-15-0/product-variant-15-0-product_variant_template_reassign"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-variant&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
+<p>Be able to assign a unique variant to a multi-variant template.</p>
+<p><strong>Table of contents</strong></p>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
+<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
+<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
+<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
+<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
+<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="usage">
+<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
+<p>To assign variants, go to a single variant product template.</p>
+<ol class="arabic simple">
+<li>In actions, choose: <em>Reassign variant</em>.</li>
+<li>Choose the target product template.</li>
+<li>Choose the variant attributes if available (otherwise you won’t be
+able to reassign the variant)</li>
+<li>Click on <em>Reassign</em>.</li>
+</ol>
+</div>
+<div class="section" id="bug-tracker">
+<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
+<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-variant/issues">GitHub Issues</a>.
+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
+<a class="reference external" href="https://github.com/OCA/product-variant/issues/new?body=module:%20product_variant_template_reassign%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
+<p>Do not contact contributors directly about support or help with technical issues.</p>
+</div>
+<div class="section" id="credits">
+<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
+<div class="section" id="authors">
+<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
+<ul class="simple">
+<li>Tecnativa</li>
+</ul>
+</div>
+<div class="section" id="contributors">
+<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
+<ul class="simple">
+<li><a class="reference external" href="https://tecnativa.com">Tecnativa</a><ul>
+<li>David Vidal</li>
+<li>Pedro M. Baeza</li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="maintainers">
+<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
+<p>This module is maintained by the OCA.</p>
+<a class="reference external image-reference" href="https://odoo-community.org">
+<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
+</a>
+<p>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.</p>
+<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
+<p><a class="reference external image-reference" href="https://github.com/chienandalu"><img alt="chienandalu" src="https://github.com/chienandalu.png?size=40px" /></a></p>
+<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-variant/tree/15.0/product_variant_template_reassign">OCA/product-variant</a> project on GitHub.</p>
+<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
+</div>
+</div>
+</div>
+</body>
+</html>
diff --git a/product_variant_template_reassign/tests/__init__.py b/product_variant_template_reassign/tests/__init__.py
new file mode 100644
index 000000000..f86c166af
--- /dev/null
+++ b/product_variant_template_reassign/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_product_variant_reassign
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..7b8c39839
--- /dev/null
+++ b/product_variant_template_reassign/tests/test_product_variant_reassign.py
@@ -0,0 +1,62 @@
+# Copyright 2024 Tecnativa - David Vidal
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from odoo import Command
+from odoo.tests import Form, TransactionCase
+
+
+class ProductVariantReassignCase(TransactionCase):
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.att_color = cls.env["product.attribute"].create({"name": "Color (test)"})
+        cls.att_color_blue = cls.env["product.attribute.value"].create(
+            {"name": "Blue", "attribute_id": cls.att_color.id}
+        )
+        cls.att_color_red = cls.env["product.attribute.value"].create(
+            {"name": "Red", "attribute_id": cls.att_color.id}
+        )
+        cls.att_color_green = cls.env["product.attribute.value"].create(
+            {"name": "Green", "attribute_id": cls.att_color.id}
+        )
+        cls.color_scarf = cls.env["product.template"].create(
+            {
+                "name": "Test color_scarf",
+                "attribute_line_ids": [
+                    Command.create(
+                        {
+                            "attribute_id": cls.att_color.id,
+                            "value_ids": [
+                                Command.set(
+                                    [cls.att_color_blue.id, cls.att_color_red.id]
+                                ),
+                            ],
+                        }
+                    )
+                ],
+            }
+        )
+        cls.green_scarf = cls.env["product.template"].create(
+            {"name": "Test color_scarf", "default_code": "TST-GREEN"}
+        )
+
+    def test_reassign_product(self):
+        existing_color_scarves = self.color_scarf.product_variant_ids
+        wiz_form = Form(
+            self.env["reassign.variant"].with_context(active_id=self.green_scarf.id)
+        )
+        self.assertTrue(
+            self.color_scarf in wiz_form.allowed_target_product_template_ids
+        )
+        wiz_form.target_product_template_id = self.color_scarf
+        self.assertTrue(self.att_color_green in wiz_form.allowed_attribute_value_ids)
+        self.assertFalse(self.att_color_red in wiz_form.allowed_attribute_value_ids)
+        wiz_form.attribute_value_ids.add(self.att_color_green)
+        wiz = wiz_form.save()
+        wiz.reassign()
+        new_color_scarve = self.color_scarf.product_variant_ids - existing_color_scarves
+        self.assertEqual(
+            new_color_scarve.product_template_attribute_value_ids.product_attribute_value_id,
+            self.att_color_green,
+        )
+        self.assertEqual(new_color_scarve.default_code, "TST-GREEN")
+        self.assertFalse(bool(self.green_scarf.exists()))
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..870a4cbc2
--- /dev/null
+++ b/product_variant_template_reassign/wizards/reassign_variant.py
@@ -0,0 +1,151 @@
+# 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 not product_template.check_access_rights("create", raise_exception=False):
+            raise UserError(
+                _(
+                    "Only users with permissions to create products can reassign variants"
+                )
+            )
+        if product_template and product_template.product_variant_count != 1:
+            raise UserError(_("You can only reassign unique variant products"))
+        res = super().default_get(fields_list)
+        if product_template:
+            res["origin_product_template_id"] = product_template.id
+        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),
+                    ("uom_id", "=", wiz.origin_product_template_id.uom_id.id),
+                    ("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 _get_field_spec(self) -> dict:
+        """Override to add rules"""
+        return {
+            "default_code": "first_not_null",
+        }
+
+    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 selected attributes didn't generate a variant in the target template"
+                )
+            )
+        try:
+            new_variant.ensure_one()
+        except ValueError:
+            raise UserError(
+                _(
+                    "The selected attributes 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,
+            field_spec=self._get_field_spec(),
+            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",
+        )
+        body = (
+            f'<a href="#" data-oe-model="product.product" data-oe-id="{new_variant.id}">'
+            f'{new_variant.display_name}</a> {_("reassigned to this template")}'
+        )
+        self.target_product_template_id.message_post(body=body)
+        return {
+            "type": "ir.actions.act_window",
+            "res_model": "product.template",
+            "view_mode": "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..8242d7bab
--- /dev/null
+++ b/product_variant_template_reassign/wizards/reassign_variant_views.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+    <record id="reassign_variant_form" model="ir.ui.view">
+        <field name="model">reassign.variant</field>
+        <field name="arch" type="xml">
+            <form>
+                <group>
+                    <field
+                        name="origin_product_template_id"
+                        string="Variant to move"
+                        readonly="1"
+                        widget="selection"
+                    />
+                </group>
+                <group string="Select the target template">
+                    <field name="allowed_target_product_template_ids" invisible="1" />
+                    <field
+                        name="target_product_template_id"
+                        options="{'no_create': True}"
+                        required="1"
+                    />
+                    <field name="allowed_attribute_value_ids" invisible="1" />
+                    <field
+                        name="attribute_value_ids"
+                        widget="many2many_tags"
+                        options="{'no_create': True, 'no_open': True}"
+                        required="1"
+                        attrs="{'invisible': ['|', ('target_product_template_id', '=', False), ('allowed_attribute_value_ids', '=', [])]}"
+                    />
+                </group>
+                <div
+                    role="alert"
+                    class="alert alert-info"
+                    attrs="{'invisible': ['|', ('target_product_template_id', '=', False), '&amp;', ('target_product_template_id', '!=', False), ('allowed_attribute_value_ids', '!=', [])]}"
+                >
+                        <i
+                        class="fa fa-exclamation-triangle"
+                    /> No attributes available for create a new variant in the target template
+                </div>
+                <div
+                    role="alert"
+                    class="alert alert-warning"
+                    attrs="{'invisible': [('attribute_value_ids', '=', [])]}"
+                >
+                        <i
+                        class="fa fa-exclamation-triangle"
+                    /> Reassigning this template variant to the selected target
+                        <strong>can't be undone</strong>
+                </div>
+                <footer>
+                    <button
+                        name="reassign"
+                        type="object"
+                        class="btn-primary"
+                        confirm="This will merge the current template into the selected one and it can't be undone"
+                        attrs="{'invisible': [('attribute_value_ids', '=', [])]}"
+                    >Reassign</button>
+                    <button special="cancel" data-hotkey="z" string="Cancel" />
+                </footer>
+            </form>
+        </field>
+    </record>
+    <record id="reassign_variant_action" model="ir.actions.act_window">
+        <field name="name">Reassign variant</field>
+        <field name="binding_model_id" ref="product.model_product_template" />
+        <field name="res_model">reassign.variant</field>
+        <field name="view_mode">form</field>
+        <field name="target">new</field>
+    </record>
+</odoo>
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,
+)