Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Clean up filestore

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
filestore
5 Respuestas
13938 Vistas
Avatar
Michael Schmidt

We're trying to clean up our filestore since its gradually growing and way beyond 100GB right now.
We are removing the avatar from the res.partner record, then observe that the 'image' related records are deleted automatically from the ir_attachment table.

However the files in the filestore related to the ir_attachment that is deleted remain in the filestore.
Do they ever get deleted, or are permanent?


The "Base: Auto-vacuum internal data" doesn't seem to do the job.

5
Avatar
Descartar
Avatar
Auto-Matt
Mejor respuesta

I actually have a interesing case. I currently run v15 on odoo.sh and I'm exporting database to try to import it with filestore to different machine for testing and I get 'virus' warning on some file in the odoo db dump.

I was able to locate the phisical file with it's name from antivirus and tried to search for the file in ir.attachment table using the field "Stored Filename" (technical name of field 'store_fname'). Result is the file name that is physically in database dump is not found in the ir.attachment, but the file is physically in the filestore folder when doing db backup.

This is where it gets interesting... in pararel I'm tring to migrate to v17 and have my staging running with v17 version with the same database backup, and there I can find the file in ir.attachment based on it's "Stored Filename".

I want to remove the file from v15 to continue migration, but I cannot locate it.

any ideas?

0
Avatar
Descartar
Avatar
Stefan Wiselka
Mejor respuesta

The scripts, written below, are missing one very important part.
If you use method search​ on model: ir.attachment​ without defining in domain fields: res_field​ or id​, it will exclude searching files saved in image fields, i.e profile photos of the users/partners

See: https://github.com/odoo/odoo/blob/fa20b5f2fed9e683c420798dce506a86fd5e511d/odoo/addons/base/models/ir_attachment.py#L527
We must change it, and add some workaround: ('id','!=',0)
self.search([('store_fname', '=', folder + '/' + file),('id','!=',0)])

0
Avatar
Descartar
Avatar
Karsten Kinateder
Mejor respuesta

# Working in production >= odoo12


import os

def cleanup_filestore(self):
# Get all attachments in the filestore

# Get the current database filestore
filestore_path = self._filestore()
# Get all folders from filestore_path
filestore_folders = os.listdir(filestore_path)
for folder in filestore_folders:
# Get all files per folder
folder_files = os.listdir(join(filestore_path, folder))
# Iterate over files
for file in folder_files:
attach_exist = self.search([('store_fname', '=', folder + '/' + file)])
print(str(attach_exist))
if len(attach_exist) == 0 and folder in file:
​ ​ ​ # folder in file is to check if it is a file created by odoo and to prvent to delete other
os.unlink(join(filestore_path, folder, file))


0
Avatar
Descartar
Avatar
Muhammad Amir Nazir
Mejor respuesta

In Odoo, the "Base: Auto-vacuum internal data" module is designed to periodically delete old records from the database to free up space and improve performance. However, this module does not delete files from the filestore that are no longer referenced in the database.

To clean up the filestore, you will need to manually delete the files that are no longer needed. One way to do this is to use a script that iterates over the ir_attachment table and checks which files are no longer referenced in the database. You can then delete the corresponding files from the filestore.

Here is an example of how you might implement this in Python:

Copy codeimport os

from odoo import api, models

class IrAttachment(models.Model):
    _inherit = 'ir.attachment'

    @api.model
    def cleanup_filestore(self):
        # Get all attachments in the filestore
        filestore_path = self.env['ir.config_parameter'].get_param('ir_attachment.location')
        filestore_files = os.listdir(filestore_path)

        # Iterate over all attachments in the database
        for attachment in self.search([]):
            # Check if the attachment's file is in the filestore
            if attachment.store_fname in filestore_files:
                # Check if the attachment is referenced in the database
                if not self.search([('store_fname', '=', attachment.store_fname)]):
                    # The attachment is not referenced in the database, so delete the file
                    os.unlink(os.path.join(filestore_path, attachment.store_fname))

You can run this script periodically to clean up the filestore, or you can run it manually as needed.

I hope this information is helpful. If you have any further questions about managing the filestore in Odoo, please don't hesitate to ask.


0
Avatar
Descartar
Vincent Baggerman

I suspect this comment to be written by ChatGPT. Do not run the code that is mentioned.

Arsenty Karamurza

the idea is sensible but it should iterate through files NOT db entries.

Avatar
Pablo
Mejor respuesta

Hi, how do you run it manually? thanks

0
Avatar
Descartar
DIOR27

You can run it manually by using odoo shell (type ./odoo-bin shell or odoo shell in your terminal), you need to put line by line starting with filestore_path = self.env['ir.config_parameter'].get_param('ir_attachment.location') respecting the indentation

DIOR27

Also you can create a cron with the function and executing it manually

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
Upload Large File Store to Odoo.sh Resuelto
filestore
Avatar
Avatar
1
jul 25
7685
where is the filestore folder located on odoo 18
filestore
Avatar
Avatar
1
feb 25
5360
where is filestore information saved in Odoo
filestore
Avatar
0
nov 23
6464
How to set up a Remote filestore directory in odoo.conf?
filestore
Avatar
0
mar 22
5355
File Bucket
filestore
Avatar
0
oct 21
3337
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now