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.