diff --git a/product_variant_attribute_name_manager/README.rst b/product_variant_attribute_name_manager/README.rst new file mode 100644 index 00000000000..9a2fec2fc6b --- /dev/null +++ b/product_variant_attribute_name_manager/README.rst @@ -0,0 +1,96 @@ +====================================== +Product Variant Attribute Name Manager +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:14da79e97a5c24f8d1c23804556490c54e67087ea746262fb48499ca16c13f22 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/17.0/product_variant_attribute_name_manager + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-17-0/product-attribute-17-0-product_variant_attribute_name_manager + :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-attribute&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Manage how to display the attributes on the product variant name. + +- Choose if you want to display the name of the attribute before its + value. +- Choose if you want to display the attribute value in the product name. +- Set a short name to be displayed as the attribute's name. +- Set the order of the attributes for each product. +- Choose if you want to display attribute value name for Single Variant + Attribute + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* ForgeFlow + +Contributors +------------ + +- Oriol Villamayor +- Daniel Reis +- Nikul Chaudhary +- Jordi Masvidal +- John Herholz + +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-JordiMForgeFlow| image:: https://github.com/JordiMForgeFlow.png?size=40px + :target: https://github.com/JordiMForgeFlow + :alt: JordiMForgeFlow + +Current `maintainer `__: + +|maintainer-JordiMForgeFlow| + +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_variant_attribute_name_manager/__init__.py b/product_variant_attribute_name_manager/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_variant_attribute_name_manager/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_variant_attribute_name_manager/__manifest__.py b/product_variant_attribute_name_manager/__manifest__.py new file mode 100644 index 00000000000..2c02ee42bfb --- /dev/null +++ b/product_variant_attribute_name_manager/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "Product Variant Attribute Name Manager", + "summary": "Manage how to display the attributes on the product variant name.", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/product-attribute", + "category": "Product", + "version": "17.0.1.0.0", + "depends": ["product"], + "data": ["views/product_variant_attribute_name_manager_view.xml"], + "license": "AGPL-3", + "auto_install": False, + "installable": True, + "maintainers": ["JordiMForgeFlow"], +} diff --git a/product_variant_attribute_name_manager/i18n/es.po b/product_variant_attribute_name_manager/i18n/es.po new file mode 100644 index 00000000000..ef51680672c --- /dev/null +++ b/product_variant_attribute_name_manager/i18n/es.po @@ -0,0 +1,118 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_variant_attribute_name_manager +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-24 08:18+0000\n" +"PO-Revision-Date: 2024-07-24 08:18+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_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_template_attribute_line__sequence +msgid "Determine the display order" +msgstr "Determina el orden de visualización" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_attribute_name +msgid "Display Attribute Name/Short Name on Product Variant" +msgstr "Mostrar Nombre Atributo/Nombre Corto en Variante de Producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_attribute_value +msgid "Display Attribute Value on Product Variant" +msgstr "Mostrar Valor de Atributo en Variante de Producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_no_variant_attribute +msgid "Display No Variant Attributes on Product Variant" +msgstr "No Mostrar Atributos de Variante en Variante de Producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_single_variant_attribute +msgid "Display Single Variant Attributes on Product Variant" +msgstr "Mostrar Atributos de Variante Única en Variante de Producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__single_variant_attribute +msgid "" +"Display the attribute value of the variant when the variant has only one " +"value" +msgstr "Mostrar el valor del atributo de la variante cuando ésta sólo tiene un valor" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__short_name +msgid "Displayed as the variant attribute name." +msgstr "Se visualiza como variante del nombre del atributo." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_no_variant_attribute +msgid "If checked, it will display the no variant attribute." +msgstr "Si está marcada, se mostrará el atributo no variante." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_single_variant_attribute +msgid "If checked, it will display the single variant attribute." +msgstr "Si está marcada, se mostrará el atributo de variante única." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_attribute_name +msgid "" +"If checked, it will display the variant attribute name before its value." +msgstr "" +"Si está marcada, mostrará el nombre del atributo variante antes de su valor." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_attribute_value +msgid "" +"If checked, it will display the variant attribute value in the product name." +msgstr "" +"Si está marcada, mostrará el valor del atributo variante en el nombre del " +"producto." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__single_variant_attribute +msgid "If checked, it will display variants that have only one variant." +msgstr "Si está marcada, mostrará las variantes que sólo tengan una variante." + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_attribute +msgid "Product Attribute" +msgstr "Atributo de producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_template_attribute_line +msgid "Product Template Attribute Line" +msgstr "Línea de atributo de la plantilla de producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_template_attribute_value +msgid "Product Template Attribute Value" +msgstr "Valor de Atributo del Modelo de Producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_product +msgid "Product Variant" +msgstr "Producto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_template_attribute_line__sequence +msgid "Sequence" +msgstr "Secuencia" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__short_name +msgid "Short Name" +msgstr "Nombre Corto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_product__product_template_variant_value_ids +msgid "Variant Values" +msgstr "Valores de las variantes" \ No newline at end of file diff --git a/product_variant_attribute_name_manager/i18n/it.po b/product_variant_attribute_name_manager/i18n/it.po new file mode 100644 index 00000000000..be45efaaa7a --- /dev/null +++ b/product_variant_attribute_name_manager/i18n/it.po @@ -0,0 +1,117 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_variant_attribute_name_manager +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-07-24 08:20+0000\n" +"PO-Revision-Date: 2024-07-24 08:20+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_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_template_attribute_line__sequence +msgid "Determine the display order" +msgstr "Determina l'ordine di visualizzazione" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_attribute_name +msgid "Display Attribute Name/Short Name on Product Variant" +msgstr "Mostra nome attributo/abbreviazione nella variante prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_attribute_value +msgid "Display Attribute Value on Product Variant" +msgstr "Mostra valore attributo nella variante prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_no_variant_attribute +msgid "Display No Variant Attributes on Product Variant" +msgstr "Mostra attributi non della variante nella variante prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_single_variant_attribute +msgid "Display Single Variant Attributes on Product Variant" +msgstr "Mostra attributi con singolo valore nella variante prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__single_variant_attribute +msgid "" +"Display the attribute value of the variant when the variant has only one " +"value" +msgstr "Visualizzare il valore dell'attributo della variante quando la variante ha un solo valore" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__short_name +msgid "Displayed as the variant attribute name." +msgstr "Visualizzato come nome della variante attributo." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_no_variant_attribute +msgid "If checked, it will display the no variant attribute." +msgstr "Se selezionata, visualizzerà l'attributo non della variante." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_single_variant_attribute +msgid "If checked, it will display the single variant attribute." +msgstr "Se abilitato, mostrerà l'attributo della singola variante." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_attribute_name +msgid "" +"If checked, it will display the variant attribute name before its value." +msgstr "Se abilitato, mostrerà il nome dell'attributo prima del valore." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_attribute_value +msgid "" +"If checked, it will display the variant attribute value in the product name." +msgstr "" +"Se selezionata, visualizzerà il valore dell'attributo variante nel nome " +"prodotto." + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__single_variant_attribute +msgid "If checked, it will display variants that have only one variant." +msgstr "Se è selezionata, verranno visualizzate le varianti che hanno una sola variante." + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_attribute +msgid "Product Attribute" +msgstr "Attributo prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_template_attribute_line +msgid "Product Template Attribute Line" +msgstr "Riga attributo modello prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_template_attribute_value +msgid "Product Template Attribute Value" +msgstr "Valore attributo modello prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_template_attribute_line__sequence +msgid "Sequence" +msgstr "Sequenza" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__short_name +msgid "Short Name" +msgstr "Nome corto" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_product__product_template_variant_value_ids +msgid "Variant Values" +msgstr "Valori variante" \ No newline at end of file diff --git a/product_variant_attribute_name_manager/i18n/product_variant_attribute_name_manager.pot b/product_variant_attribute_name_manager/i18n/product_variant_attribute_name_manager.pot new file mode 100644 index 00000000000..355550df21f --- /dev/null +++ b/product_variant_attribute_name_manager/i18n/product_variant_attribute_name_manager.pot @@ -0,0 +1,91 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_variant_attribute_name_manager +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_template_attribute_line__sequence +msgid "Determine the display order" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_attribute_name +msgid "Display Attribute Name/Short Name on Product Variant" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_attribute_value +msgid "Display Attribute Value on Product Variant" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_no_variant_attribute +msgid "Display No Variant Attributes on Product Variant" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__display_single_variant_attribute +msgid "Display Single Variant Attributes on Product Variant" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__short_name +msgid "Displayed as the variant attribute name." +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_no_variant_attribute +msgid "If checked, it will display the no variant attribute." +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_single_variant_attribute +msgid "If checked, it will display the single variant attribute." +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_attribute_name +msgid "" +"If checked, it will display the variant attribute name before its value." +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,help:product_variant_attribute_name_manager.field_product_attribute__display_attribute_value +msgid "" +"If checked, it will display the variant attribute value in the product name." +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_attribute +msgid "Product Attribute" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_template_attribute_line +msgid "Product Template Attribute Line" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model,name:product_variant_attribute_name_manager.model_product_template_attribute_value +msgid "Product Template Attribute Value" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_template_attribute_line__sequence +msgid "Sequence" +msgstr "" + +#. module: product_variant_attribute_name_manager +#: model:ir.model.fields,field_description:product_variant_attribute_name_manager.field_product_attribute__short_name +msgid "Short Name" +msgstr "" diff --git a/product_variant_attribute_name_manager/models/__init__.py b/product_variant_attribute_name_manager/models/__init__.py new file mode 100644 index 00000000000..8b5a4564d18 --- /dev/null +++ b/product_variant_attribute_name_manager/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_attribute +from . import product_product diff --git a/product_variant_attribute_name_manager/models/product_attribute.py b/product_variant_attribute_name_manager/models/product_attribute.py new file mode 100644 index 00000000000..1da74eb5d88 --- /dev/null +++ b/product_variant_attribute_name_manager/models/product_attribute.py @@ -0,0 +1,68 @@ +from odoo import fields, models + + +class ProductAttribute(models.Model): + _inherit = "product.attribute" + + short_name = fields.Char(help="Displayed as the variant attribute name.") + display_attribute_value = fields.Boolean( + "Display Attribute Value on Product Variant", + default=True, + help="If checked, it will display the variant " + "attribute value in the product name.", + ) + display_attribute_name = fields.Boolean( + "Display Attribute Name/Short Name on Product Variant", + help="If checked, it will display the variant attribute name before its value.", + ) + + display_no_variant_attribute = fields.Boolean( + "Display No Variant Attributes on Product Variant", + help="If checked, it will display the no variant attribute.", + ) + + display_single_variant_attribute = fields.Boolean( + "Display Single Variant Attributes on Product Variant", + help="If checked, it will display the single variant attribute.", + ) + + single_variant_attribute = fields.Boolean( + "Display the attribute value of the variant when the variant " + "has only one value", + help="If checked, it will display variants that have only one variant.", + ) + + +class ProductTemplateAttributeLine(models.Model): + _inherit = "product.template.attribute.line" + + sequence = fields.Integer(help="Determine the display order", index=True) + + +class ProductTemplateAttributeValue(models.Model): + _inherit = "product.template.attribute.value" + + def _get_combination_name(self): + """Gets the combination name of all the attributes. + If active, it will display the name or short name before its value. + The order of the attributes is defined by the user""" + display_ptav_list = [] + for ptav in sorted(self, key=lambda seq: seq.attribute_line_id.sequence): + if not ptav.attribute_id.display_attribute_value: + continue + if not ptav.attribute_id.display_single_variant_attribute: + if not ptav._filter_single_value_lines(): + continue + if not ptav.attribute_id.display_no_variant_attribute: + if not ptav._without_no_variant_attributes(): + continue + if ptav.attribute_id.display_attribute_name: + display_ptav_list.append( + "{}: {}".format( + ptav.attribute_id.short_name or ptav.attribute_id.name, + ptav.name, + ) + ) + else: + display_ptav_list.append(ptav.name) + return ", ".join(display_ptav_list) diff --git a/product_variant_attribute_name_manager/models/product_product.py b/product_variant_attribute_name_manager/models/product_product.py new file mode 100644 index 00000000000..e7fb625f13e --- /dev/null +++ b/product_variant_attribute_name_manager/models/product_product.py @@ -0,0 +1,17 @@ +from odoo import fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + product_template_variant_value_ids = fields.Many2many( + domain=lambda self: self._get_domain_attribute_line_id(), + ) + + def _get_domain_attribute_line_id(self): + domoain = [ + "|", + ("attribute_line_id.value_count", ">", 1), + ("attribute_line_id.attribute_id.single_variant_attribute", "=", True), + ] + return domoain diff --git a/product_variant_attribute_name_manager/pyproject.toml b/product_variant_attribute_name_manager/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/product_variant_attribute_name_manager/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_variant_attribute_name_manager/readme/CONTRIBUTORS.md b/product_variant_attribute_name_manager/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..3ea08b0756d --- /dev/null +++ b/product_variant_attribute_name_manager/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- Oriol Villamayor \<\> +- Daniel Reis \<\> +- Nikul Chaudhary \<\> +- Jordi Masvidal \<\> +- John Herholz \<\> diff --git a/product_variant_attribute_name_manager/readme/DESCRIPTION.md b/product_variant_attribute_name_manager/readme/DESCRIPTION.md new file mode 100644 index 00000000000..25f0020a59a --- /dev/null +++ b/product_variant_attribute_name_manager/readme/DESCRIPTION.md @@ -0,0 +1,9 @@ +Manage how to display the attributes on the product variant name. + +- Choose if you want to display the name of the attribute before its + value. +- Choose if you want to display the attribute value in the product name. +- Set a short name to be displayed as the attribute's name. +- Set the order of the attributes for each product. +- Choose if you want to display attribute value name for Single Variant + Attribute diff --git a/product_variant_attribute_name_manager/static/description/icon.png b/product_variant_attribute_name_manager/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_variant_attribute_name_manager/static/description/icon.png differ diff --git a/product_variant_attribute_name_manager/static/description/index.html b/product_variant_attribute_name_manager/static/description/index.html new file mode 100644 index 00000000000..2df66ad9fff --- /dev/null +++ b/product_variant_attribute_name_manager/static/description/index.html @@ -0,0 +1,438 @@ + + + + + +Product Variant Attribute Name Manager + + + +
+

Product Variant Attribute Name Manager

+ + +

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

+

Manage how to display the attributes on the product variant name.

+
    +
  • Choose if you want to display the name of the attribute before its +value.
  • +
  • Choose if you want to display the attribute value in the product name.
  • +
  • Set a short name to be displayed as the attribute’s name.
  • +
  • Set the order of the attributes for each product.
  • +
  • Choose if you want to display attribute value name for Single Variant +Attribute
  • +
+

Table of contents

+ +
+

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

+
    +
  • ForgeFlow
  • +
+
+ +
+

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:

+

JordiMForgeFlow

+

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

+

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

+
+
+
+ + diff --git a/product_variant_attribute_name_manager/tests/__init__.py b/product_variant_attribute_name_manager/tests/__init__.py new file mode 100644 index 00000000000..c492ad2d0bb --- /dev/null +++ b/product_variant_attribute_name_manager/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_variant_attribute_name_manager diff --git a/product_variant_attribute_name_manager/tests/test_product_variant_attribute_name_manager.py b/product_variant_attribute_name_manager/tests/test_product_variant_attribute_name_manager.py new file mode 100644 index 00000000000..f83fc0c1086 --- /dev/null +++ b/product_variant_attribute_name_manager/tests/test_product_variant_attribute_name_manager.py @@ -0,0 +1,187 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.tests import tagged +from odoo.tests.common import TransactionCase + + +@tagged("post_install", "-at_install") +class TestProductTemplateAttributeValue(TransactionCase): + def setUp(self): + super().setUp() + + self.product_attr_value_obj = self.env["product.attribute.value"] + self.product_attr_obj = self.env["product.attribute"] + self.computer = self.env["product.template"].create({"name": "Super Computer"}) + + self._add_ssd_attribute() + self._add_ram_attribute() + self._add_hdd_attribute() + self._add_color_attribute() + + def _add_ssd_attribute(self): + self.ssd_attribute = self.product_attr_obj.create( + { + "name": "Memory", + "short_name": "Mem", + "display_attribute_name": True, + "sequence": 1, + } + ) + self.ssd_256 = self.product_attr_value_obj.create( + {"name": "256 GB", "attribute_id": self.ssd_attribute.id, "sequence": 1} + ) + self.ssd_512 = self.product_attr_value_obj.create( + {"name": "512 GB", "attribute_id": self.ssd_attribute.id, "sequence": 2} + ) + + self.computer_ssd_attribute_lines = self.env[ + "product.template.attribute.line" + ].create( + { + "product_tmpl_id": self.computer.id, + "attribute_id": self.ssd_attribute.id, + "value_ids": [(6, 0, [self.ssd_256.id, self.ssd_512.id])], + "sequence": 2, + } + ) + + def _add_ram_attribute(self): + self.ram_attribute = self.product_attr_obj.create( + {"name": "RAM", "display_attribute_name": True, "sequence": 2} + ) + self.ram_8 = self.product_attr_value_obj.create( + {"name": "8 GB", "attribute_id": self.ram_attribute.id, "sequence": 1} + ) + self.ram_16 = self.product_attr_value_obj.create( + {"name": "16 GB", "attribute_id": self.ram_attribute.id, "sequence": 2} + ) + self.ram_32 = self.product_attr_value_obj.create( + {"name": "32 GB", "attribute_id": self.ram_attribute.id, "sequence": 3} + ) + self.computer_ram_attribute_lines = self.env[ + "product.template.attribute.line" + ].create( + { + "product_tmpl_id": self.computer.id, + "attribute_id": self.ram_attribute.id, + "value_ids": [(6, 0, [self.ram_8.id, self.ram_16.id, self.ram_32.id])], + "sequence": 3, + } + ) + + def _add_hdd_attribute(self): + self.hdd_attribute = self.product_attr_obj.create( + {"name": "HDD", "sequence": 3} + ) + self.hdd_1 = self.product_attr_value_obj.create( + {"name": "1 To", "attribute_id": self.hdd_attribute.id, "sequence": 1} + ) + self.hdd_2 = self.product_attr_value_obj.create( + {"name": "2 To", "attribute_id": self.hdd_attribute.id, "sequence": 2} + ) + + self.computer_hdd_attribute_lines = self.env[ + "product.template.attribute.line" + ].create( + { + "product_tmpl_id": self.computer.id, + "attribute_id": self.hdd_attribute.id, + "value_ids": [(6, 0, [self.hdd_1.id, self.hdd_2.id])], + "sequence": 1, + } + ) + + def _add_color_attribute(self): + self.color_attribute = self.env["product.attribute"].create( + { + "name": "COLOR", + "sequence": 4, + "display_attribute_name": True, + } + ) + self.color_white = self.env["product.attribute.value"].create( + {"name": "White", "attribute_id": self.color_attribute.id, "sequence": 1} + ) + + self.computer_color_attribute_lines = self.env[ + "product.template.attribute.line" + ].create( + { + "product_tmpl_id": self.computer.id, + "attribute_id": self.color_attribute.id, + "value_ids": [(6, 0, [self.color_white.id])], + "sequence": 4, + } + ) + + def test_display_attribute_name(self): + variant_names = [ + variant.product_template_attribute_value_ids._get_combination_name() + for variant in self.env["product.product"].search( + [("product_tmpl_id", "=", self.computer.id)] + ) + ] + + self.assertIn( + "1 To, Mem: 256 GB, RAM: 8 GB", + variant_names, + "Variant name extension not found", + ) + self.assertIn( + "2 To, Mem: 512 GB, RAM: 16 GB", + variant_names, + "Variant name extension not found", + ) + self.assertNotIn( + "1 To, 256 GB, 8 GB", variant_names, "Variant name extension not correct" + ) + self.assertNotIn( + "Mem: 256 GB, 1 To, RAM: 8 GB", + variant_names, + "Variant name extension not correct", + ) + + self.color_attribute.display_single_variant_attribute = True + + variant_names = [ + variant.product_template_attribute_value_ids._get_combination_name() + for variant in self.env["product.product"].search( + [("product_tmpl_id", "=", self.computer.id)] + ) + ] + + self.assertIn( + "1 To, Mem: 256 GB, RAM: 8 GB, COLOR: White", + variant_names, + "Variant name extension not found", + ) + + def test_display_attribute_value(self): + # Do not display RAM Attribute value + self.ram_attribute.write({"display_attribute_value": False}) + variant_names = [ + variant.product_template_attribute_value_ids._get_combination_name() + for variant in self.env["product.product"].search( + [("product_tmpl_id", "=", self.computer.id)] + ) + ] + + self.assertIn( + "1 To, Mem: 256 GB", + variant_names, + "Variant name extension not found", + ) + self.assertIn( + "2 To, Mem: 512 GB", + variant_names, + "Variant name extension not found", + ) + self.assertNotIn( + "1 To, Mem: 256 GB, RAM: 8 GB", + variant_names, + "Variant name extension not correct", + ) + self.assertNotIn( + "2 To, Mem: 512 GB, RAM: 8 GB", + variant_names, + "Variant name extension not correct", + ) diff --git a/product_variant_attribute_name_manager/views/product_variant_attribute_name_manager_view.xml b/product_variant_attribute_name_manager/views/product_variant_attribute_name_manager_view.xml new file mode 100644 index 00000000000..58621eb2d03 --- /dev/null +++ b/product_variant_attribute_name_manager/views/product_variant_attribute_name_manager_view.xml @@ -0,0 +1,44 @@ + + + + product.template.product.form + product.template + + + + + + + + + + product.attribute.form + product.attribute + + + + + + + + + + + + + + + + + +