Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Clean up filestore

Odebírat

Get notified when there's activity on this post

This question has been flagged
filestore
5 Odpovědi
14137 Zobrazení
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
Zrušit
Avatar
Auto-Matt
Nejlepší odpověď

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
Zrušit
Avatar
Stefan Wiselka
Nejlepší odpověď

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
Zrušit
Avatar
Karsten Kinateder
Nejlepší odpověď

# 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
Zrušit
Avatar
Muhammad Amir Nazir
Nejlepší odpověď

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
Zrušit
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
Nejlepší odpověď

Hi, how do you run it manually? thanks

0
Avatar
Zrušit
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!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Upload Large File Store to Odoo.sh Vyřešeno
filestore
Avatar
Avatar
1
čvc 25
7812
where is the filestore folder located on odoo 18
filestore
Avatar
Avatar
1
úno 25
5637
where is filestore information saved in Odoo
filestore
Avatar
0
lis 23
6662
How to set up a Remote filestore directory in odoo.conf?
filestore
Avatar
0
bře 22
5499
File Bucket
filestore
Avatar
0
říj 21
3421
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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