← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~therp-nl/ocb-web/7.0_lp1261332_better_report_name into lp:ocb-web

 

Ronald Portier (Therp) has proposed merging lp:~therp-nl/ocb-web/7.0_lp1261332_better_report_name into lp:ocb-web.

Requested reviews:
  OpenERP Community Backports (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/~therp-nl/ocb-web/7.0_lp1261332_better_report_name/+merge/219901

Port 6.1 proposal to 7.0.

Please ignore the typo in the branchname (1261332 instead of 126322).
-- 
https://code.launchpad.net/~therp-nl/ocb-web/7.0_lp1261332_better_report_name/+merge/219901
Your team OpenERP Community Backports is requested to review the proposed merge of lp:~therp-nl/ocb-web/7.0_lp1261332_better_report_name into lp:ocb-web.
=== modified file 'addons/web/controllers/main.py'
--- addons/web/controllers/main.py	2014-02-21 11:58:55 +0000
+++ addons/web/controllers/main.py	2014-05-16 20:21:31 +0000
@@ -1751,16 +1751,24 @@
             report = zlib.decompress(report)
         report_mimetype = self.TYPES_MAPPING.get(
             report_struct['format'], 'octet-stream')
-        file_name = action.get('name', 'report')
-        if 'name' not in action:
-            reports = req.session.model('ir.actions.report.xml')
-            res_id = reports.search([('report_name', '=', action['report_name']),],
-                                    0, False, False, context)
-            if len(res_id) > 0:
-                file_name = reports.read(res_id[0], ['name'], context)['name']
-            else:
-                file_name = action['report_name']
+        file_name = action['report_name']
+        # Try to get current object model and their ids from context
+        if 'context' in action:  
+            action_context = action['context']
+            if (action_context.get('active_model')
+            and action_context['active_ids']):
+                # Use built-in ORM method to get data from DB
+                m = req.session.model(action_context['active_model'])
+                r = m.name_get(action_context['active_ids'], context)
+                # Parse result to create a better filename
+                item_names = [item[1] or str(item[0]) for item in r]
+                if action.get('name'):
+                    item_names.insert(0, action['name'])
+                file_name = '-'.join(item_names)
         file_name = '%s.%s' % (file_name, report_struct['format'])
+        # Create safe filename
+        p = re.compile('[/:(")<>|?*]|(\\\)')
+        file_name = p.sub('_', file_name)
 
         return req.make_response(report,
              headers=[


Follow ups