When managing products in Odoo, assigning the right attributes and attribute values is crucial—especially for variants and eCommerce filtering. But doing this manually for each product import can be time-consuming.
In this blog, we’ll walk through how to use Automated Actions in Odoo to automatically assign attributes and their values to imported products based on their category. No coding required—just Odoo’s built-in tools!
Use Case
Suppose you import a batch of new products, and you want:
- All products under the category "Shoes" to be automatically assigned:
- Attribute: Size -> Values: 42, 43, 44
- Attribute: Color -> Values: Black, White
Rather than doing this manually, we'll configure an automated rule in Odoo that does it for you.
Prerequisites
1. Activate Developer Mode (Settings -> Activate Developer Mode) 2. Ensure the following are enabled:
- Product Variants (Inventory -> Configuration -> Settings) - Automated Actions (installed via Technical Features)
Step-by-Step Guide
Step 1: Prepare Your Product Attributes
- Sales -> Products -> Attributes
- Create or confirm attributes and their values (e.g., Size: 42, 43, 44; Color: Black, White)
- Via Studio create field Category (in our case it is x_Studio_product_category)
Step 2: Create a Server Action
- Go to Settings -> Technical -> Actions -> Server Actions - Name: Auto-Assign Attributes
- Model: Product Template
- Action To Do: Execute Python Code
Python Code:
category = record.categ_id
# Find all product attributes linked to this category via custom field
attributes = env['product.attribute'].search([
('x_studio_product_category', '=', category.id)
])
# Clear old attribute lines
record.attribute_line_ids.unlink()
# Create new attribute lines
for attr in attributes:
record.attribute_line_ids.create({
'attribute_id': attr.id,
'value_ids': [(6, 0, attr.value_ids.ids)],
'product_tmpl_id': record.id
})
# Force variant regeneration
record._create_variant_ids()
Step 3: Create an Automated Action
- Settings -> Technical -> Automation -> Automated Actions - Name: Assign Attributes on Import
- Model: Product Template
- Trigger: On Creation
- Action To Do: Execute a Server Action - Server Action: Auto-Assign Attributes
Test It
1. Import a CSV of products with category set to "Shoes"
2. Go to one of the product templates
3. Under the Variants tab, attributes Size (42, 43, 44) and Color (Black, White) should be assigned
We are preparing 2 products in 2 different categories
If you have issues creating excel export one product in CSV (if you export product in CSV you are able to import image as well)
RESULTS:
Tips & Considerations
- Ensure attribute values exist before automation runs - Add conditional logic for other categories as needed - Test in staging before enabling in production
With a simple automated action, you can save hours of manual product configuration during import. Odoo's flexible automation tools enable you to create powerful rules-even without being a developer.