OpenERP v7 - Where are document Attachments stored?

Zarshed Ali
Zarshed Ali
5000
| 2 1 2
Asked on 1/29/15, 11:23 AM
0
vote
3486 Views

In OpenERP v7, by default, attachments are stored in the database. 
You may choose to store them on the filesystem by setting 
an ir.config.parameter (Settings->Technical->Parameters-System parameters) named ir_attachment.location

Example if you set ir_attachment.location to file:///filestore

They will be stored in the filesystem at openerp root_path/filestore, 
the new system uses sha1 to generate the filename so that duplicate files don't take more space.

Only the file:/// scheme is implemented, modules can implement additional scheme like amazons3:///

In database mode the data is stored in ir_attachment.db_datas.
Filestore mode file name is stored in ir_attachment.db_datas_fname.

Those names suck but we kept them for backwards compatibility.

No automatic conversion mechanism exists.

If you set this parameter existing attachments remain stored in the database, only NEW ones will be stored in the filesystem. 
But the system will try both location so it's not a problem (db_datas is checked first then db_datas_fname).

If you remove this parameter you should manually store back the files in the database because the system will only look in the database.

************************************************************************************************************************************************

 

In case you need to migrate your attachments after changing the storage from database to filestore, 
you can use the following script (use only on OpenERP 7.x):

#!/usr/bin/python
import xmlrpclib
username = 'admin' #the user
pwd = 'password'      #the password of the user
dbname = 'database'    #the database

# Get the uid
sock_common = xmlrpclib.ServerProxy ('<URL>/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)
sock = xmlrpclib.ServerProxy('<URL>/xmlrpc/object')
def migrate_attachment(att_id):
    # 1. get data
    att = sock.execute(dbname, uid, pwd, 'ir.attachment', 'read', att_id, ['datas'])            

    data = att['datas']

    # Re-Write attachment
    a = sock.execute(dbname, uid, pwd, 'ir.attachment', 'write', [att_id], {'datas': data})

# SELECT attachments:
att_ids = sock.execute(dbname, uid, pwd, 'ir.attachment', 'search', [('store_fname','=',False)])

cnt = len(att_ids)        
i = 0
for id in att_ids:
    att = sock.execute(dbname, uid, pwd, 'ir.attachment', 'read', id, ['datas','parent_id'])

    migrate_attachment(id)
    print 'Migrated ID %d (attachment %d of %d)' % (id,i,cnt)
    i = i + 1

print "done ..."

 

After running the script, clean up your ir_attachments table:

update ir_attachment set db_datas = null where store_fname is not null
vacuum (full, analyze) ir_attachment

Replace <URL> with your OpenERP installation URL.

Zarshed Ali
Zarshed Ali
5000
| 2 1 2
Answered on 1/29/15, 11:27 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This forum is for HiTechnologia Employees & just Odoo general knowledge purpose only.

Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 1/29/15, 11:23 AM
Seen: 3486 times
Last updated: 1/29/15, 11:27 AM