Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Clean up filestore

Subscriure's

Get notified when there's activity on this post

This question has been flagged
filestore
5 Respostes
14089 Vistes
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
Best Answer

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
Best Answer

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
Best Answer

# 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
Best Answer

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
Best Answer

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Upload Large File Store to Odoo.sh Solved
filestore
Avatar
Avatar
1
de jul. 25
7790
where is the filestore folder located on odoo 18
filestore
Avatar
Avatar
1
de febr. 25
5578
where is filestore information saved in Odoo
filestore
Avatar
0
de nov. 23
6620
How to set up a Remote filestore directory in odoo.conf?
filestore
Avatar
0
de març 22
5462
File Bucket
filestore
Avatar
0
d’oct. 21
3406
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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