Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] product_attribute_set: allow displaying attributes for product variants #174

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions attribute_set/models/attribute_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
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"
Expand Down Expand Up @@ -224,6 +228,18 @@

return attribute_eview

def _get_attribute_set_allowed_model(self):
return self.model_id

Check warning on line 232 in attribute_set/models/attribute_attribute.py

View check run for this annotation

Codecov / codecov/patch

attribute_set/models/attribute_attribute.py#L232

Added line #L232 was not covered by tests

@api.depends("model_id")
def _compute_allowed_attribute_set_ids(self):
AttributeSet = self.env["attribute.set"]

Check warning on line 236 in attribute_set/models/attribute_attribute.py

View check run for this annotation

Codecov / codecov/patch

attribute_set/models/attribute_attribute.py#L236

Added line #L236 was not covered by tests
for record in self:
allowed_models = record._get_attribute_set_allowed_model()
record.allowed_attribute_set_ids = AttributeSet.search(

Check warning on line 239 in attribute_set/models/attribute_attribute.py

View check run for this annotation

Codecov / codecov/patch

attribute_set/models/attribute_attribute.py#L238-L239

Added lines #L238 - L239 were not covered by tests
[("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)]}}
Expand Down
3 changes: 2 additions & 1 deletion attribute_set/views/attribute_attribute_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@
domain="[('model_id', '=', model_id)]"
/>
<field name="sequence" />
<field name="allowed_attribute_set_ids" invisible="1" />
<field
name="attribute_set_ids"
widget="many2many_tags"
domain="[('model_id', '=', model_id)]"
domain="[('id', 'in', allowed_attribute_set_ids)]"
options="{'no_create': 1}"
invisible="context.get('from_attribute_set')"
/>
Expand Down
1 change: 1 addition & 0 deletions product_attribute_set/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import attribute_attribute
from . import product_category
from . import product
14 changes: 14 additions & 0 deletions product_attribute_set/models/attribute_attribute.py
Original file line number Diff line number Diff line change
@@ -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()

Check warning on line 11 in product_attribute_set/models/attribute_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/attribute_attribute.py#L11

Added line #L11 was not covered by tests
if self.model_id.model == "product.product":
res |= self.env["ir.model"].search([("model", "=", "product.template")])
return res

Check warning on line 14 in product_attribute_set/models/attribute_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/attribute_attribute.py#L13-L14

Added lines #L13 - L14 were not covered by tests
14 changes: 12 additions & 2 deletions product_attribute_set/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,15 @@
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"))]

Check warning on line 62 in product_attribute_set/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product.py#L62

Added line #L62 was not covered by tests
30 changes: 30 additions & 0 deletions product_attribute_set/views/product.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Product Template -->
<record id="product.product_template_action" model="ir.actions.act_window">
<field name="context">
{"include_native_attribute": 1, "search_default_filter_to_sell": 1}
Expand All @@ -17,6 +18,7 @@
name="attribute_set_id"
nolabel="1"
context="{'default_model_id': %(product.model_product_template)d}"
force_save="1"
/>
</div>
</xpath>
Expand Down Expand Up @@ -47,4 +49,32 @@
</xpath>
</field>
</record>
<!-- Product Variant -->
<record id="product.product_normal_action" model="ir.actions.act_window">
<field name="context">
{"include_native_attribute": 1}
</field>
</record>
<record id="product.product_normal_action_sell" model="ir.actions.act_window">
<field name="context">
{"include_native_attribute": 1, "search_default_filter_to_sell": 1}
</field>
</record>
<!-- Do not display all the attributes in the easy edit view -->
<record id="product_variant_easy_edit_view" model="ir.ui.view">
<field
name="name"
>product.product.view.form.easy - product_attribute_set</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_variant_easy_edit_view" />
<field name="arch" type="xml">
<xpath expr="//group[@name='packaging']/.." position="after">
<group>
<group name="product_attributes" string="Attributes" invisible="1">
<separator name="attributes_placeholder" />
</group>
</group>
</xpath>
</field>
</record>
</odoo>
2 changes: 1 addition & 1 deletion product_attribute_set/views/product_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<field name="parent_id" position="after">
<field
name="attribute_set_id"
domain="[('model_id', '=', 'product.template')]"
domain="[('model_id', 'in', ('product.template', 'product.product'))]"
class="oe_inline"
/>
</field>
Expand Down
Loading