This question has been flagged
2 Replies
3774 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

Avatar
Discard
Author Best Answer

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

Thanks

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):
            os.makedirs(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):
            try:
                with open(full_path, 'wb') as fp:
                    fp.write(bin_value)
            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.

Thanks

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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

Author

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