Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
2150 Prikazi

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
Opusti
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
Opusti
Avtor

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)])

Avtor

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

Avtor

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 Odgovori Prikazi Aktivnost
0
jun. 25
2868
1
avg. 24
1883
1
nov. 23
4420
3
nov. 24
10737
1
jun. 21
2966