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.

0

Change filename of binary field (client side)

By
Vedran Mikac
on 12/10/13, 4:29 PM 1,560 views

XLS file is generated in onChange event. Binary data gets saved in the field, and can be downloaded and opened without a problem. Only problem is that filename offered by the browser's save dialog is modelName_modelID (until model gets saved).

Snippet from _view.xml

 <field name="node_candidates_fn" invisible="1"/>
 <field name="node_candidates" filename="node_candidates_fn" readonly="True" nolabel="0"/>

node_candidates_fn is set in _defaults using:

'node_candidates_fn': 'NodeCandidatesFromDefault.xls',

And when writing a binary file using:

to_save = {'node_candidates': base64_data,  
           'node_candidates_fn': "NodeCandidatesFromSaveToBinary.xls"}
self.write(cr, uid, ids[0], to_save)

To be on the safe side, result from the onChange event (after saving to binary field) is:

 return {'value': {'node_candidates': base64_data,
                   'node_candidates_fn': 'NodeCandidatesFromOnChangeRetVal.xls'}}

When XLS file gets generated, the download widget shows: "Download NodeCandidatesFromSaveToBinary.xls", but when I click on the link, the filename that is offered by the browser's save dialog is modelName_modelId.

Note: If I save the model, filename offered by the browser's save dialog is NodeCandidatesFromSaveToBinary.xls. Saving model is not preferred!

1
Vedran Mikac
On 12/11/13, 2:55 PM

Solution to the problem can be found on Launchpad under OpenERP Web bug with title: "no filename from saveas_ajax"

Apply the patch, and things should work as expected.

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

0 follower(s)

Stats

Asked: 12/10/13, 4:29 PM
Seen: 1560 times
Last updated: 3/16/15, 8:10 AM