openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #02482
lp:~yann-papouin/ocb-web/6.1-bug-1261322-useful-report-filename into lp:ocb-web/6.1
Yann Papouin has proposed merging lp:~yann-papouin/ocb-web/6.1-bug-1261322-useful-report-filename into lp:ocb-web/6.1.
Requested reviews:
OpenERP Community Backports Team (ocb)
Related bugs:
Bug #1261322 in OpenERP Web: "[6.1][7.0][trunk] Default report filename is useless in daily use"
https://bugs.launchpad.net/openerp-web/+bug/1261322
For more details, see:
https://code.launchpad.net/~yann-papouin/ocb-web/6.1-bug-1261322-useful-report-filename/+merge/200007
--
https://code.launchpad.net/~yann-papouin/ocb-web/6.1-bug-1261322-useful-report-filename/+merge/200007
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~yann-papouin/ocb-web/6.1-bug-1261322-useful-report-filename into lp:ocb-web/6.1.
=== modified file 'addons/web/controllers/main.py'
--- addons/web/controllers/main.py 2013-07-04 14:32:57 +0000
+++ addons/web/controllers/main.py 2013-12-24 10:40:40 +0000
@@ -1862,6 +1862,25 @@
break
time.sleep(self.POLLING_DELAY)
+
+ file_name = action['report_name']
+ # Try to get current object model and their ids from context
+ if action.has_key('context'):
+ action_context = action.get('context',{})
+ if action_context.has_key('active_model') and action_context.has_key('active_id'):
+ action_active_model = action_context.get('active_model','')
+ action_active_ids = action_context.get('active_ids', [])
+ if action_active_model and action_active_ids:
+ # Use built-in ORM method to get data from DB
+ m = req.session.model(action_active_model)
+ r = m.read(action_active_ids, ['name'], context)
+ # Parse result to create a better filename
+ for i, item in enumerate(r):
+ if item.has_key('name'):
+ if i == 0:
+ file_name = ('%s') % (item['name'])
+ else:
+ file_name = ('%s-%s') % (file_name, item['name'])
report = base64.b64decode(report_struct['result'])
if report_struct.get('code') == 'zlib':
@@ -1870,7 +1889,7 @@
report_struct['format'], 'octet-stream')
return req.make_response(report,
headers=[
- ('Content-Disposition', 'attachment; filename="%s.%s"' % (action['report_name'], report_struct['format'])),
+ ('Content-Disposition', 'attachment; filename="%s.%s"' % (file_name, report_struct['format'])),
('Content-Type', report_mimetype),
('Content-Length', len(report))],
cookies={'fileToken': int(token)})
Follow ups