Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2137 Представления

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?

Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Автор

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

Автор

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

Автор

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 Ответы Просмотры Активность
0
июн. 25
2836
1
авг. 24
1856
1
нояб. 23
4387
Delete my account Решено
3
нояб. 24
10697
1
июн. 21
2942