Skip to Content
Menu
This question has been flagged
3 Replies
10701 Views

I am migrating a database with thousands of products. Trying to export large numbers of images using the Odoo web interface is not possible due to resource limits on the server.

How can I export the external ids and the product images directly from the Odoo database?

Avatar
Discard
Author Best Answer

Looking at openerp/osv/orm.py in _get_external_ids() we can see that the external ids are stored in "ir_model_data" and can be tied to the models using "ir_model_data"."model" and "ir_model_data"."res_id".  So to dump product external ids and images to a CSV:

copy (select "ir_model_data"."module" || '.' || "ir_model_data"."name" as "id", encode("product_product"."image",'base64') as "image" from "product_product" left join "ir_model_data" on (("ir_model_data"."model" = 'product.product') and ("product_product"."id" = "ir_model_data"."res_id")) where ("product_product"."image" is not null)) to '/tmp/product.product.images.csv' with csv header;

Or to pipe data from the source server to another server, connect from the remote server to the source database using psql:

\copy (select "ir_model_data"."module" || '.' || "ir_model_data"."name" as "id", encode("product_product"."image",'base64') as "image" from "product_product" left join "ir_model_data" on (("ir_model_data"."model" = 'product.product') and ("product_product"."id" = "ir_model_data"."res_id")) where ("product_product"."image" is not null)) to 'product.product.images.csv' with csv header;

Alternatively, I suppose it would be possible to:

  • Export the database ids and the external ids using the Odoo web interface.
  • Export the database ids and images directly from the database.
  • Use a third-party tool and the database ids to associate the external ids with the images.
  • Upload the images to Odoo.

But exporting the external id directly, as described above, would in many cases be preferable.

Another alternative would be to script oerplib to stream data from an old database to a new database.

Avatar
Discard
Best Answer

Hi, i know this is kind of an old post but i would like to know where did you found the binaries for the images, im performing a similar export from odoo 12 and the interface export of images is broken

i used some similar queries to yours in this post but to no avail, there are no images in product_templates or product_product.

after some research i found out that for odoo 12 images are saved in ir_attachement in the field: datas_fname.

so i got this query

Select "id", "res_name", "datas_fname" from ir_attachment WHERE res_model = 'product.template' and "datas_fname" is not null;

and the result is this sample: 

https://docs.google.com/spreadsheets/u/7/d/1QR_HTSiYxUXOSl-2nS0MaDY7QHRMbux-43RhbB1eYak/edit?usp=sharing

there are no binaries in this table.

i made:

Select * from ir_attachment WHERE res_model = 'product.template' and res_field = 'image' and 'db_datas' is not null

to check all the fields from the table and got this other data set.

https://docs.google.com/spreadsheets/d/1g1zZrTLu56MU7S5O5nzg-QQtsLa8QaE7jflddnRb9Wo/edit?usp=sharing

where i got: no binaries at all

where di you got the binaries for your export?

kindly thank you very much.

Avatar
Discard
Best Answer

Apologies for my ignorance but the where do you run the copy instruction? On a terminal, on postgresql, on python?

Avatar
Discard
Author

From a terminal, run psql to access your PostgreSQL database, then run the \copy command from psql. And of course test before you do anything in a production environment.