跳至内容
菜单
此问题已终结
1 回复
1583 查看

HI

I need to transfer products with variants from one Odoo database to another and have one requirement:

I need to keep the exact external identifier for both product.template and product.product records. 

I need specially to preserve the external identifier for product.product (Product Variants) because later on I'll have to transfer stock moves and, yes, what is referenced in stock moves, sales, purchases, is product.product (and not product.template).

I've successfully could already export products with variants exporting "attribute_line_ids/attribute_id/id" and "attribute_line_ids/value_ids/id" and import them in the destination database and everything is OK, products with variants are replicated but at the end variants (product.product records) have no external identifier, and I need them.

Can someone help, please?

形象
丢弃

I got the same problem. Did you solve it?

最佳答案

Hi,

When transferring products with variants between two Odoo databases, Odoo does not automatically preserve the external identifiers (`xml_id`) for product variants (`product.product`), even though they are essential because all transactional records—like stock moves, sales, and purchases—reference the product variant model, not the product template. During export, Odoo only includes the business data, not the technical metadata stored in `ir.model.data`, where these external IDs are kept. As a result, when you import the products into another database, new variants are created with new internal and external IDs, breaking references for future data transfers. To fix this, you need to explicitly export and re-import the `ir.model.data` records related to `product.template` and `product.product` or use an XML-based export/import instead of CSV. The XML format automatically retains external IDs in `<record id="...">` tags. Another option is to run a small Python script after import that programmatically restores the same external IDs for each variant. The most reliable process is to first ensure all attributes and values exist with the same external IDs, then import the product templates and variants using XML or by preloading `ir.model.data` entries. This guarantees that both databases share identical external IDs, ensuring future imports—such as stock moves or order lines—can link to the correct product variants without conflicts.


refer:

1.https://www.odoo.com/documentation/19.0/applications/essentials/export_import_data.html

2, https://www.cybrosys.com/blog/how-to-import-product-attributes-and-product-variants-in-odoo-17


Hope it helps.

形象
丢弃