Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
2276 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

Auteur

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

Auteur

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!

Gerelateerde posts Antwoorden Weergaven Activiteit
0
jun. 25
3099
1
aug. 24
2111
1
nov. 23
4687
3
nov. 24
10993
1
jun. 21
3141