Skip to Content
Menú
This question has been flagged
1 Respondre
2141 Vistes

Hello there 🙂,

due to changes in our portfolio, archived products are piling up in our database (Odoo 14 E) and their images are taking up more and more space. We have loads of high resolutions images for our shop.

Unfortunately it takes a lot of time (so much time) to delete them one after the other. So I wondered if there is a script or an app for that?

Avatar
Descartar
Best Answer

Hi,

You can create a server action that executes the python code and delete all the images.


below code is not tested, still you can try and modify if needed

products = env['product.product'].search([])

for pro in products:

​ pro['image_1920'] = ''

pro.product_template_image_ids.unlink()

pro.product_variant_image_ids.unlink()





Thanks

Avatar
Descartar
Autor

Hi Niyas Paphy, thank you so much! But I want to delete archived images only. Who do put that into the `.search([])`?

products = env['product.product'].search([('active', '=', False)])

Autor

Right "active", I forgot that. Thank you. I've just tested it and it worked! Thank you so much, problem solved.

Autor

I've tested it a little more and I have to give a **WARNING**. It is possible that the archived product (`product.product`) is a variant of an **active** product (`product.template`).

For example you go to a product template and remove some attributes of variants (sizes for example). If those variants have been sold before, Odoo will archive them instead of deleting them. So you might end up having active and inactive variants of the same product (template) at the same time.

This code will delete the main image and added e-commerce images of the product template as well as of it's archived variant.

In my case, I just use the last line
`pro.product_variant_image_ids.unlink()` as these are definitely only delete images of this particular archived variant. And variant pictures make up most of the space anyway.

The problem is still solved for me, thanks again, Niyas Raphy!

Related Posts Respostes Vistes Activitat
0
de juny 25
2838
1
d’ag. 24
1860
1
de nov. 23
4389
3
de nov. 24
10699
1
de juny 21
2945