Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2293 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
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!

Powiązane posty Odpowiedzi Widoki Czynność
0
cze 25
3114
1
sie 24
2120
1
lis 23
4697
3
lis 24
11003
1
cze 21
3149