From 8ac4a42885d8d37f2ac6e12a2c05b959e3412a56 Mon Sep 17 00:00:00 2001 From: JordiMForgeFlow Date: Thu, 23 Nov 2023 15:57:59 +0100 Subject: [PATCH 1/4] [IMP] product_attribute_set: allow displaying attributes for product variants --- product_attribute_set/models/product.py | 14 ++++++++++++-- product_attribute_set/views/product.xml | 18 ++++++++++++++++++ .../views/product_category.xml | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/product_attribute_set/models/product.py b/product_attribute_set/models/product.py index 540d4dcf..185d335d 100644 --- a/product_attribute_set/models/product.py +++ b/product_attribute_set/models/product.py @@ -48,5 +48,15 @@ def _onchange_categ_id(self): self.attribute_set_id = self.categ_id.attribute_set_id -# TODO : add the 'attribute.set.owner.mixin' to product.product in order to display -# Attributes in Variants. +class ProductProduct(models.Model): + + _inherit = ["product.product", "attribute.set.owner.mixin"] + _name = "product.product" + + attribute_set_id = fields.Many2one( + related="product_tmpl_id.attribute_set_id", store=True + ) + + @api.model + def _get_attribute_set_owner_model(self): + return [("model", "in", ("product.product", "product.template"))] diff --git a/product_attribute_set/views/product.xml b/product_attribute_set/views/product.xml index 6419280a..647d69b9 100644 --- a/product_attribute_set/views/product.xml +++ b/product_attribute_set/views/product.xml @@ -17,6 +17,7 @@ name="attribute_set_id" nolabel="1" context="{'default_model_id': %(product.model_product_template)d}" + force_save="1" /> @@ -47,4 +48,21 @@ + + + product.product.view.form.easy - product_attribute_set + product.product + + + + + + + + + + + diff --git a/product_attribute_set/views/product_category.xml b/product_attribute_set/views/product_category.xml index ea962411..8709d081 100644 --- a/product_attribute_set/views/product_category.xml +++ b/product_attribute_set/views/product_category.xml @@ -8,7 +8,7 @@ From c65fafbe75f4e1c0e9325567f0076ed0482f3e88 Mon Sep 17 00:00:00 2001 From: JordiMForgeFlow Date: Wed, 6 Dec 2023 09:03:29 +0100 Subject: [PATCH 2/4] [IMP] product_attribute_set: allow assigning variant attribute to template set --- product_attribute_set/models/__init__.py | 1 + .../models/attribute_attribute.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 product_attribute_set/models/attribute_attribute.py diff --git a/product_attribute_set/models/__init__.py b/product_attribute_set/models/__init__.py index 533c5a5a..d3ddd3de 100644 --- a/product_attribute_set/models/__init__.py +++ b/product_attribute_set/models/__init__.py @@ -1,2 +1,3 @@ +from . import attribute_attribute from . import product_category from . import product diff --git a/product_attribute_set/models/attribute_attribute.py b/product_attribute_set/models/attribute_attribute.py new file mode 100644 index 00000000..80161185 --- /dev/null +++ b/product_attribute_set/models/attribute_attribute.py @@ -0,0 +1,14 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AttributeAttribute(models.Model): + _inherit = "attribute.attribute" + + def _get_attribute_set_allowed_model(self): + res = super()._get_attribute_set_allowed_model() + if self.model_id.model == "product.product": + res |= self.env["ir.model"].search([("model", "=", "product.template")]) + return res From a837d4f99d04c2487b88c353403951dbd4f68534 Mon Sep 17 00:00:00 2001 From: JordiMForgeFlow Date: Wed, 6 Dec 2023 09:03:56 +0100 Subject: [PATCH 3/4] [IMP] product_attribute_set: show native fields for variants --- product_attribute_set/views/product.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/product_attribute_set/views/product.xml b/product_attribute_set/views/product.xml index 647d69b9..648cf3db 100644 --- a/product_attribute_set/views/product.xml +++ b/product_attribute_set/views/product.xml @@ -1,5 +1,6 @@ + {"include_native_attribute": 1, "search_default_filter_to_sell": 1} @@ -48,6 +49,17 @@ + + + + {"include_native_attribute": 1} + + + + + {"include_native_attribute": 1, "search_default_filter_to_sell": 1} + + Date: Wed, 6 Dec 2023 09:04:37 +0100 Subject: [PATCH 4/4] [IMP] attribute_set: abstract logic for attribute set domain in attributes --- attribute_set/models/attribute_attribute.py | 16 ++++++++++++++++ attribute_set/views/attribute_attribute_view.xml | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/attribute_set/models/attribute_attribute.py b/attribute_set/models/attribute_attribute.py index 064c8131..8202af80 100644 --- a/attribute_set/models/attribute_attribute.py +++ b/attribute_set/models/attribute_attribute.py @@ -97,6 +97,10 @@ class AttributeAttribute(models.Model): column1="attribute_id", column2="attribute_set_id", ) + allowed_attribute_set_ids = fields.Many2many( + comodel_name="attribute.set", + compute="_compute_allowed_attribute_set_ids", + ) attribute_group_id = fields.Many2one( "attribute.group", "Attribute Group", required=True, ondelete="cascade" @@ -224,6 +228,18 @@ def _build_attribute_eview(self): return attribute_eview + def _get_attribute_set_allowed_model(self): + return self.model_id + + @api.depends("model_id") + def _compute_allowed_attribute_set_ids(self): + AttributeSet = self.env["attribute.set"] + for record in self: + allowed_models = record._get_attribute_set_allowed_model() + record.allowed_attribute_set_ids = AttributeSet.search( + [("model_id", "in", allowed_models.ids)] + ) + @api.onchange("model_id") def onchange_model_id(self): return {"domain": {"field_id": [("model_id", "=", self.model_id.id)]}} diff --git a/attribute_set/views/attribute_attribute_view.xml b/attribute_set/views/attribute_attribute_view.xml index c1bb7042..7b7cca27 100644 --- a/attribute_set/views/attribute_attribute_view.xml +++ b/attribute_set/views/attribute_attribute_view.xml @@ -72,10 +72,11 @@ domain="[('model_id', '=', model_id)]" /> +