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

[FIX] product_attribute_set: auto update attributes by updating attribute_set_id #201

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions product_attribute_set/demo/product_attribute.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@
<field name="field_id" eval="ref('product.field_product_template__weight')" />
<field name="attribute_group_id" ref="computer_transport_attribute_group" />
<field name="attribute_set_ids" eval="[(4, ref('computer_attribute_set'))]" />
<field name="model_id" ref="product.model_product_template" />
</record>
<record id="computer_volume_attribute" model="attribute.attribute">
<field name="nature">native</field>
<field name="field_id" eval="ref('product.field_product_template__volume')" />
<field name="attribute_group_id" ref="computer_transport_attribute_group" />
<field name="attribute_set_ids" eval="[(4, ref('computer_attribute_set'))]" />
<field name="model_id" ref="product.model_product_template" />
</record>
</odoo>
8 changes: 8 additions & 0 deletions product_attribute_set/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
if self.categ_id and not self.attribute_set_id:
self.attribute_set_id = self.categ_id.attribute_set_id

@api.onchange("attribute_set_id")
def _onchange_attribute_set_id(self):
"""Trigger _get_view_fields implicitly to auto update attributes in the UI"""
if self.attribute_set_id:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be tested with Form(). Could you check ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will see

view_id = self.env.ref("product.product_template_only_form_view").id
view = self.get_views([(view_id, "form")], {})
view.get("models")

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

View check run for this annotation

Codecov / codecov/patch

product_attribute_set/models/product.py#L54-L56

Added lines #L54 - L56 were not covered by tests


class ProductProduct(models.Model):

Expand Down
Loading