diff options
| author | Fabien Meghazi <fme@openerp.com> | 2012-02-08 11:39:35 +0100 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2012-02-08 11:39:35 +0100 |
| commit | 739b0d4861dff958d80c2c6fa5c86b1c3ed329a7 (patch) | |
| tree | 121ccd369a0683531153320d1eb6c243afe77e0c /addons/web/controllers/main.py | |
| parent | 5daa33329e9363210ffe0f6623177c8f6488f0ae (diff) | |
[FIX] Binary#save_as does not send context. Breaks some accounting downloadable reports.
Example of broken report was : Accounting > Reporting > Legal Reports > Belgium Statements > Periodical VAT Declaration
bzr revid: fme@openerp.com-20120208103935-cv9nn9kg1vssosgm
Diffstat (limited to 'addons/web/controllers/main.py')
| -rw-r--r-- | addons/web/controllers/main.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 5338604e76b..9cb0698be4a 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1257,6 +1257,37 @@ class Binary(openerpweb.Controller): ('Content-Disposition', 'attachment; filename="%s"' % filename)]) @openerpweb.httprequest + def saveas_ajax(self, req, data, token): + jdata = simplejson.loads(data) + model = jdata['model'] + field = jdata['field'] + id = jdata.get('id', None) + filename_field = jdata.get('filename_field', None) + context = jdata.get('context', dict()) + + context = req.session.eval_context(context) + Model = req.session.model(model) + fields = [field] + if filename_field: + fields.append(filename_field) + if id: + res = Model.read([int(id)], fields, context)[0] + else: + res = Model.default_get(fields, context) + filecontent = base64.b64decode(res.get(field, '')) + if not filecontent: + raise ValueError("No content found for field '%s' on '%s:%s'" % + (field, model, id)) + else: + filename = '%s_%s' % (model.replace('.', '_'), id) + if filename_field: + filename = res.get(filename_field, '') or filename + return req.make_response(filecontent, + headers=[('Content-Type', 'application/octet-stream'), + ('Content-Disposition', 'attachment; filename="%s"' % filename)], + cookies={'fileToken': int(token)}) + + @openerpweb.httprequest def upload(self, req, callback, ufile): # TODO: might be useful to have a configuration flag for max-length file uploads try: |
