Product classification and attribute constraints
Project description
Product Class
Product Class
This module introduces Product Classes for standardizing product setup and attribute management. It allows you to:
Define Product Classes — Group related products into classes (e.g., “Furniture”, “Electronics”)
Constrain Attributes per Class — Specify which attributes are allowed for each class
Mark Required Attributes — Designate certain attributes as mandatory for products in that class
Enforce Validation — Prevent products from using attributes outside their class or missing required attributes
Key Features
Bridge Model (``product.class.attribute.line``) — Manages the relationship between classes and attributes, storing both allowed attributes and a required flag
Strict Validation — Products assigned to a class must:
Use only attributes defined in that class
Provide values for all required attributes
UI Enforcement — Attribute selection in product forms is restricted by the class domain filter
Management Views — Full CRUD interface for product classes (Inventory > Configuration > Product Classes, Sales > Configuration > Product Classes)
Technical Architecture
product.class — Main product classification model
product.class.attribute.line — Bridge model linking classes to attributes with a required flag
product.attribute (inherited) — Extended with reverse one-to-many to track which classes use it
product.template (inherited) — Added class validation and computed required-attribute tracking
Table of contents
Usage
Usage
1. Create a Product Class
Navigation: Inventory → Configuration → Product Classes (or Sales → Configuration → Product Classes)
Click Create button
Enter a Product Class Name (e.g., “Chairs”)
In the Attributes section:
Click Add a line
Select an Attribute from the dropdown
Check Required if products of this class must define this attribute
Repeat to add more attributes
Click Save
Example: “Furniture” Class
Attribute |
Required |
Notes |
|---|---|---|
Color |
✓ |
All furniture must have a color |
Size |
✓ |
Sizes vary by product |
Material |
Optional (not all items specify) |
|
Finish |
Optional polish/coating |
2. Assign a Product to a Class
Navigation: Inventory → Products → Products
Create or edit a product
Find the Product Class field in the Attributes & Variants tab (added by this module)
Select the class (e.g., “Furniture”)
The form will now restrict Attributes to only those allowed by the class
3. Add Attribute Lines to a Classed Product
Once a class is selected, you can add attribute lines:
Go to the Attributes & Variants tab
In Attribute Lines, click Add a line
The Attribute field dropdown is now filtered to show only class-allowed attributes
Select an attribute and provide values
Validation will fail if:
You select an attribute not in the class → Error: “has attribute lines that do not belong”
You leave out a required attribute → Error: “is missing required attributes”
4. Remove an Attribute from a Class
Scenario: Your “Furniture” class allowed “Color” but wants to retire it.
Navigate to the class
In Attributes, find the “Color” line and delete it
Odoo will raise an error if products in this class still use Color
Fix: Remove Color from all products in the class first, then retry the class update
Workflow Example
Step 1: Set Up “Chairs” Class
Color (required)
Size (required)
Leg Material (optional)
Step 2: Create a “Wooden Chair” Product
Assign class: “Chairs”
Add attribute “Color” = Red (satisfies required)
Add attribute “Size” = Large (satisfies required)
Add attribute “Leg Material” = Oak (optional, still valid)
Save ✓ Success
Step 3: Try Invalid Assignment
Assign class: “Chairs”
Add attribute “Color” = Blue (satisfies required)
Try to save without Size → Error: “is missing required attributes for the selected class ‘Chairs’: Size”
Add Size = Medium
Save ✓ Success
Class Attribute Line Model
The bridge model product.class.attribute.line stores:
Field |
Type |
Purpose |
|---|---|---|
class_id |
Many2one |
Product class (required, cascade delete) |
attribute_id |
Many2one |
Product attribute (required) |
required |
Boolean |
If true, products must define it |
Constraint: A class cannot configure the same attribute twice (unique on class_id + attribute_id).
Constraints & Validations
Class Constraint (_check_attribute_ids_used_by_products)
Prevents removing an attribute from a class if products still use it
Error: “Cannot remove attributes used in products assigned to class…”
Product Constraint (_check_class_attributes)
Ensures all attribute lines belong to the class
Ensures all required attributes are defined
Error: “Product ‘…’ has attribute lines that do not belong to the selected class ‘…’”
Error: “Product ‘…’ is missing required attributes for the selected class ‘…’”
Advanced: Access Control
User (base.group_user): Can create/read/write product classes and their attributes
System/Admin (base.group_system): Full CRUD including delete
Product class attribute lines follow the same access rules.
Bug Tracker
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
Credits
Maintainers
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
Current maintainers:
This module is part of the OCA/product-attribute project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file odoo_addon_product_class-19.0.1.0.0.2-py3-none-any.whl.
File metadata
- Download URL: odoo_addon_product_class-19.0.1.0.0.2-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13550d1207c9d9b3e51615d9fe6abfc06c085314b22a6067b0715d646f3ff5d4
|
|
| MD5 |
c7b29bc840aee2aecbc25fba8cd1e325
|
|
| BLAKE2b-256 |
603c23103330f2917a5c57f764e3f049356b3ed9d69c71290c2d88fd71bb48dd
|