Odoo Help

Welcome!

This community 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.

2

Change random name of stored attachments

By
Pascal Tremblay
on 1/6/15, 6:40 AM 916 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

1

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 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.

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

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
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

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!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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