Skip to content

Commit

Permalink
Merge PR #174 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Jul 19, 2024
2 parents 6b88800 + 0567ff8 commit 9157fa8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 4 deletions.
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 @@ 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"
Expand Down Expand Up @@ -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)]}}
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 @@ -73,10 +73,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()
if self.model_id.model == "product.product":
res |= self.env["ir.model"].search([("model", "=", "product.template")])
return res
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 @@ 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"))]
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

0 comments on commit 9157fa8

Please sign in to comment.