Skip to content

[19.0][ADD] product_class: classes to group product attributes#2273

Open
Ricardoalso wants to merge 1 commit intoOCA:19.0from
camptocamp:product_class
Open

[19.0][ADD] product_class: classes to group product attributes#2273
Ricardoalso wants to merge 1 commit intoOCA:19.0from
camptocamp:product_class

Conversation

@Ricardoalso
Copy link
Copy Markdown

This module introduces Product Classes to group product attributes and standardize product setup.

@Ricardoalso Ricardoalso marked this pull request as draft April 23, 2026 10:06
@Ricardoalso Ricardoalso marked this pull request as ready for review April 23, 2026 11:17
Comment thread product_class/views/product_template_views.xml Outdated
<xpath expr="//field[@name='attribute_line_ids']" position="attributes">
<attribute
name="domain"
>[('attribute_id', 'in', class_id.attribute_ids.ids if class_id else [])]</attribute>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This domain doesn't seem to be working. See video below:

Screen.Recording.2026-04-23.at.8.41.03.AM.mov

The constraint catches the issue and prevents saving the record, but the UI still allows to select wrong attributes.

AFAIR you can't have expressions like this in the domain attribute, so that may be why it's not working.

The way to work around this typical case is to have an intermediate allowed_attribute_ids non-stored computed field. At least in previous versions, maybe in 19.0 there's a better way that I'm not aware of

Copy link
Copy Markdown
Author

@Ricardoalso Ricardoalso Apr 23, 2026

Choose a reason for hiding this comment

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

Hm, tricky situation here 🤔

The domain doesn’t work even with the allowed_attribute_ids approach, and the only thing preventing the user from setting an incorrect attribute is the _check_class_attributes constraint. I could override the web_name_search method, but that feels like overkill and adds complexity for limited UX benefit.

I’m open to suggestions

Thanks 🙏

Copy link
Copy Markdown
Author

@Ricardoalso Ricardoalso Apr 23, 2026

Choose a reason for hiding this comment

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

@ivantodorovich handled it with the approach we discussed about ce5ea6a

Thanks again 🚀

EDIT (context):

Using parent.class_id.attribute_ids directly does not work and triggers :

Invalid composed field class_id.attribute_ids in domain of <field name="attribute_id"> ([('id', 'in', parent.class_id.attribute_ids)] if parent.class_id else [])

Relating to the comment :

AFAIR you can't have expressions like this in the domain attribute, so that may be why it's not working.

normalize_domain handles it

>>> from odoo.fields import Command, Domain
>>> normalize_domain([('id', 'in', [1,2])] if True else [])
[('id', 'in', [1, 2])]
>>> normalize_domain([('id', 'in', [1,2])] if False else [])
[(1, '=', 1)]

Comment thread product_class/__manifest__.py
Comment thread product_class/tests/test_product_class.py Outdated
Comment thread product_class/models/product_class.py
Comment thread product_class/models/product_template.py Outdated
Copy link
Copy Markdown
Contributor

@ivantodorovich ivantodorovich left a comment

Choose a reason for hiding this comment

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

LG.

Small comments, pre-approving

Comment thread product_class/models/product_template.py Outdated
Comment thread product_class/views/product_attribute_views.xml Outdated
Comment thread product_class/models/product_attribute.py
Comment thread product_class/models/product_class.py Outdated
This module introduces Product Classes to group product attributes and standardize product setup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants