Comment 5 for bug 1252458

Revision history for this message
Anton Chepurov (anton-chepurov) wrote :

Florent THOMAS and others,

Binary fields seem to work fine for downloading files only when binary fields appear on already existing records, but not when the record is just being created.

E.g. in Florent's case, the binary's parent record does not yet exist in DB, so it doesn't have an ID, and consequently int(id) produces an error.

Therefore, neither the original version of main.py, nor the fixed one will work with new records (typically Transient records, I guess).

A possible yet ugly solution for this would be to first store the record and then reopen it by its ID.
Consider a working example in http://bazaar.launchpad.net/~openerp/openobject-server/trunk/view/head:/openerp/addons/base/module/wizard/base_export_language.py.
Here, act_getfile() first writes to the 'data' binary field, and then reopens the same object by specifying {'res_id': this.id}.
This approach works fine, but requires an extra button (kinda 'Generate my_file') to simply submit the record to DB and to reopen it.

Still waiting for a better solution.
BTW, have a look here: http://stackoverflow.com/questions/12819207/download-file-locally-in-python