forked from tfrancoi/odoo_csv_import
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Context
During a migration from Odoo 12 to Odoo 18, we encountered templates (product.template) that were imported successfully but ended up with no variants (product.product).
Root Cause Analysis
- Source data had corrupted templates - Some
product.templaterecords in Odoo 12 hadproduct_variant_count = 0andproduct_variant_ids = [] - Export was correct - Templates were exported, but there were no variants to export
- Import was correct - Templates were imported via
load()API - Missing auto-creation - Odoo's normal behavior is to auto-create a default variant when a template is created via ORM, but
load()doesn't trigger this
Impact
- 270 templates (out of 22,000+) ended up without variants in the target system
- These products couldn't be used in POs, SOs, BOMs, etc. until variants were manually created
- Related data (BOMs, supplier info) that references these products also had issues
Proposed Solution
Add an optional post-import step or flag to detect and fix templates without variants:
# After importing product.template, check for orphan templates
orphan_templates = env['product.template'].search([('product_variant_ids', '=', False)])
for tmpl in orphan_templates:
# Trigger variant creation
tmpl._create_variant_ids()
# Or manually create a default variant
env['product.product'].create({'product_tmpl_id': tmpl.id})Possible implementations:
- Warning during import - Detect and warn about templates without variants
- Auto-fix option - Add
--fix-orphan-templatesflag to automatically create default variants - Post-import verification - Add a verification step that reports data integrity issues
Workaround
We fixed this manually by running:
no_variant_templates = env['product.template'].search([('product_variant_ids', '=', False)])
for tmpl in no_variant_templates:
env['product.product'].create({
'product_tmpl_id': tmpl.id,
'default_code': tmpl.default_code,
})Environment
- Source: Odoo 12
- Target: Odoo 18
- odoo-data-flow version: latest
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels