From 12418d4ccde3a211e76352d7b3ff897ce9c0f39d Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Wed, 11 Feb 2026 20:19:38 +0100 Subject: [PATCH] [ADD] product_attribute_line_template: New module TT56921 --- product_attribute_line_template/README.rst | 89 ++++ product_attribute_line_template/__init__.py | 1 + .../__manifest__.py | 23 + .../models/__init__.py | 2 + .../models/product_attribute_template.py | 60 +++ .../models/product_template.py | 35 ++ .../pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 3 + .../readme/DESCRIPTION.md | 2 + .../readme/USAGE.md | 5 + .../security/ir.model.access.csv | 3 + .../security/security.xml | 20 + .../static/description/index.html | 442 ++++++++++++++++++ .../product_attribute_template_views.xml | 57 +++ .../views/product_template_views.xml | 21 + 15 files changed, 766 insertions(+) create mode 100644 product_attribute_line_template/README.rst create mode 100644 product_attribute_line_template/__init__.py create mode 100644 product_attribute_line_template/__manifest__.py create mode 100644 product_attribute_line_template/models/__init__.py create mode 100644 product_attribute_line_template/models/product_attribute_template.py create mode 100644 product_attribute_line_template/models/product_template.py create mode 100644 product_attribute_line_template/pyproject.toml create mode 100644 product_attribute_line_template/readme/CONTRIBUTORS.md create mode 100644 product_attribute_line_template/readme/DESCRIPTION.md create mode 100644 product_attribute_line_template/readme/USAGE.md create mode 100644 product_attribute_line_template/security/ir.model.access.csv create mode 100644 product_attribute_line_template/security/security.xml create mode 100644 product_attribute_line_template/static/description/index.html create mode 100644 product_attribute_line_template/views/product_attribute_template_views.xml create mode 100644 product_attribute_line_template/views/product_template_views.xml diff --git a/product_attribute_line_template/README.rst b/product_attribute_line_template/README.rst new file mode 100644 index 00000000000..fc1b134c7e0 --- /dev/null +++ b/product_attribute_line_template/README.rst @@ -0,0 +1,89 @@ +=============================== +Product Attribute Line Template +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:442c166d037d324d30693cffb34a4daf1095d195adc9d35b42d7ba595cec53d9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/product_attribute_line_template + :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-18-0/product-attribute-18-0-product_attribute_line_template + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows defining reusable attribute templates and applying +them to products in order to quickly generate attribute lines (without +values). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to *Settings > Attribute Templates*. +2. Create one or more attribute templates. +3. Open a product. +4. Select one or more templates in the **Attribute Templates** field. +5. The corresponding attribute lines will be automatically added. + +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 `__: + + - Pilar Vargas + +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. + +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_attribute_line_template/__init__.py b/product_attribute_line_template/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_attribute_line_template/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_attribute_line_template/__manifest__.py b/product_attribute_line_template/__manifest__.py new file mode 100644 index 00000000000..f0d5aafef96 --- /dev/null +++ b/product_attribute_line_template/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2026 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Product Attribute Line Template", + "version": "18.0.1.0.0", + "category": "Product", + "summary": "Define attribute-line templates and apply them to products", + "author": "Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/product-attribute", + "license": "AGPL-3", + "depends": [ + "sale_management", + ], + "data": [ + "security/security.xml", + "security/ir.model.access.csv", + "views/product_attribute_template_views.xml", + "views/product_template_views.xml", + ], + "installable": True, + "application": False, +} diff --git a/product_attribute_line_template/models/__init__.py b/product_attribute_line_template/models/__init__.py new file mode 100644 index 00000000000..7869087c227 --- /dev/null +++ b/product_attribute_line_template/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_attribute_template +from . import product_template diff --git a/product_attribute_line_template/models/product_attribute_template.py b/product_attribute_line_template/models/product_attribute_template.py new file mode 100644 index 00000000000..4ab54031fa8 --- /dev/null +++ b/product_attribute_line_template/models/product_attribute_template.py @@ -0,0 +1,60 @@ +# Copyright 2026 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductAttributeTemplate(models.Model): + _name = "product.attribute.template" + _description = "Product Attribute Template" + _order = "name" + + name = fields.Char(required=True, translate=True) + active = fields.Boolean(default=True) + company_id = fields.Many2one( + "res.company", + string="Company", + default=lambda self: self.env.company, + help="Leave empty to make it available for all companies.", + ) + line_ids = fields.One2many( + "product.attribute.template.line", + "template_id", + string="Attributes", + copy=True, + ) + + _sql_constraints = [ + ( + "name_company_uniq", + "unique(name, company_id)", + "A template with the same name already exists for this company.", + ) + ] + + +class ProductAttributeTemplateLine(models.Model): + _name = "product.attribute.template.line" + _description = "Product Attribute Template Line" + _order = "sequence, id" + + sequence = fields.Integer(default=10) + template_id = fields.Many2one( + "product.attribute.template", + required=True, + ondelete="cascade", + ) + attribute_id = fields.Many2one( + "product.attribute", + string="Attribute", + required=True, + help="Attribute to be added to the product when applying this template.", + ) + + _sql_constraints = [ + ( + "template_attribute_uniq", + "unique(template_id, attribute_id)", + "This attribute is already included in the template.", + ) + ] diff --git a/product_attribute_line_template/models/product_template.py b/product_attribute_line_template/models/product_template.py new file mode 100644 index 00000000000..370c3c64c2e --- /dev/null +++ b/product_attribute_line_template/models/product_template.py @@ -0,0 +1,35 @@ +# Copyright 2026 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + attribute_template_id = fields.Many2one( + "product.attribute.template", + string="Apply attribute template", + help=( + "Select a template to add its attributes to the product. " + "The selection is cleared after applying." + ), + ) + + @api.onchange("attribute_template_id") + def _onchange_attribute_template_id(self): + for product in self: + template = product.attribute_template_id + if not template: + continue + existing_attr_ids = set( + product.attribute_line_ids.mapped("attribute_id").ids + ) + for line in template.line_ids.sorted("sequence"): + attr_id = line.attribute_id.id + if attr_id not in existing_attr_ids: + product.attribute_line_ids += self.env[ + "product.template.attribute.line" + ].new({"attribute_id": attr_id}) + existing_attr_ids.add(attr_id) + product.attribute_template_id = False diff --git a/product_attribute_line_template/pyproject.toml b/product_attribute_line_template/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/product_attribute_line_template/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_attribute_line_template/readme/CONTRIBUTORS.md b/product_attribute_line_template/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..6efd183e0f6 --- /dev/null +++ b/product_attribute_line_template/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com): + + > - Pilar Vargas diff --git a/product_attribute_line_template/readme/DESCRIPTION.md b/product_attribute_line_template/readme/DESCRIPTION.md new file mode 100644 index 00000000000..76ea6b2dea3 --- /dev/null +++ b/product_attribute_line_template/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows defining reusable attribute templates and applying them +to products in order to quickly generate attribute lines (without values). diff --git a/product_attribute_line_template/readme/USAGE.md b/product_attribute_line_template/readme/USAGE.md new file mode 100644 index 00000000000..b34b2e2a592 --- /dev/null +++ b/product_attribute_line_template/readme/USAGE.md @@ -0,0 +1,5 @@ +1. Go to *Settings > Attribute Templates*. +2. Create one or more attribute templates. +3. Open a product. +4. Select one or more templates in the **Attribute Templates** field. +5. The corresponding attribute lines will be automatically added. diff --git a/product_attribute_line_template/security/ir.model.access.csv b/product_attribute_line_template/security/ir.model.access.csv new file mode 100644 index 00000000000..3213360cbb4 --- /dev/null +++ b/product_attribute_line_template/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_product_attribute_template_manager,product.attribute.template manager,model_product_attribute_template,product.group_product_manager,1,1,1,1 +access_product_attribute_template_line_manager,product.attribute.template.line manager,model_product_attribute_template_line,product.group_product_manager,1,1,1,1 diff --git a/product_attribute_line_template/security/security.xml b/product_attribute_line_template/security/security.xml new file mode 100644 index 00000000000..26968dee86b --- /dev/null +++ b/product_attribute_line_template/security/security.xml @@ -0,0 +1,20 @@ + + + + Attribute templates: multi-company + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + + + + Attribute template lines: multi-company + + + ['|', ('template_id.company_id', '=', False), ('template_id.company_id', 'in', company_ids)] + + + + diff --git a/product_attribute_line_template/static/description/index.html b/product_attribute_line_template/static/description/index.html new file mode 100644 index 00000000000..74bc61262c4 --- /dev/null +++ b/product_attribute_line_template/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Product Attribute Line Template + + + +
+

Product Attribute Line Template

+ + +

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

+

This module allows defining reusable attribute templates and applying +them to products in order to quickly generate attribute lines (without +values).

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Settings > Attribute Templates.
  2. +
  3. Create one or more attribute templates.
  4. +
  5. Open a product.
  6. +
  7. Select one or more templates in the Attribute Templates field.
  8. +
  9. The corresponding attribute lines will be automatically added.
  10. +
+
+
+

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

+ +
+
+

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.

+

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_attribute_line_template/views/product_attribute_template_views.xml b/product_attribute_line_template/views/product_attribute_template_views.xml new file mode 100644 index 00000000000..fea667405ae --- /dev/null +++ b/product_attribute_line_template/views/product_attribute_template_views.xml @@ -0,0 +1,57 @@ + + + + product.attribute.template.list + product.attribute.template + + + + + + + + + + + product.attribute.template.form + product.attribute.template + +
+ + + + + + + + + + + + + + + + + +
+
+
+ + + Attribute Templates + product.attribute.template + list,form + + + +
diff --git a/product_attribute_line_template/views/product_template_views.xml b/product_attribute_line_template/views/product_template_views.xml new file mode 100644 index 00000000000..7144ad6a4d8 --- /dev/null +++ b/product_attribute_line_template/views/product_template_views.xml @@ -0,0 +1,21 @@ + + + + product.template.form.inherit.attribute.templates + product.template + + + + + + + + + +