Odoo Help


Change random name of stored attachments

Pascal Tremblay
on 1/6/15, 6:40 AM 1,241 views

Hello there,

All the attachments are now stored on my disk but with a random long name.

I'm searching where this name is generated.

Would you know where this random/encoded filename is generated in Odoo v8?

Thanks all

P. S. I don't have this file in my installation. Should I have it in odoo? : https://github.com/odoo/odoo/blob/master/openerp/addons/base/ir/ir_attachment.py#L99 https://github.com/odoo/odoo/blob/master/openerp/addons/base/ir/ir_attachment.py#L99


Pascal Tremblay

--Pascal Tremblay--
| 5 3 7
Alma, Canada
--Pascal Tremblay--

Pascal Tremblay
On 1/6/15, 7:58 AM

I have found the file. It is not directly in the same addons folder than the others modules.


Here is the code of the _get_path() and _file_write() methods :

    def _get_path(self, cr, uid, bin_data):
        sha = hashlib.sha1(bin_data).hexdigest()

        # retro compatibility
        fname = sha[:3] + '/' + sha
        full_path = self._full_path(cr, uid, fname)
        import pdb; pdb.set_trace()
        if os.path.isfile(full_path):
            return fname, full_path        # keep existing path

        # scatter files across 256 dirs
        # we use '/' in the db (even on windows)
        fname = sha[:2] + '/' + sha
        full_path = self._full_path(cr, uid, fname)
        dirname = os.path.dirname(full_path)
        if not os.path.isdir(dirname):
        return fname, full_path

    def _file_write(self, cr, uid, value):
        bin_value = value.decode('base64')
        fname, full_path = self._get_path(cr, uid, bin_value)
        if not os.path.exists(full_path):
                with open(full_path, 'wb') as fp:
            except IOError:
                _logger.exception("_file_write writing %s", full_path)
        return fname


How could I get a filename like DE0000012.pdf rather than en encoded filename??? 

With pdb, I see that fname and full_path variables are already encoded in the above methods.




| 6 5 7
Lodz, Poland

On 1/6/15, 7:30 AM

See in  base/ir/ir_attachment.py method _get_path()

I don't have this file.... I don't even have .../addons/base folder. Is is possible that I don't have this folder?

Pascal Tremblay
on 1/6/15, 7:32 AM

the only ir_attachment.py file that I have is in .../addons/mail folder

Pascal Tremblay
on 1/6/15, 7:33 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 1/6/15, 6:40 AM
Seen: 1241 times
Last updated: 3/16/15, 8:10 AM