# adapted from https://bugs.launchpad.net/openerp-web/+bug/1261322 (which is for OpenERP 6.1) --- web/controllers/main.py 2014-01-18 01:24:31.000000000 +0100 +++ web/controllers/main.py 2014-03-28 14:11:06.949976237 +0100 @@ -1757,6 +1757,26 @@ file_name = reports.read(res_id[0], ['name'], context)['name'] else: file_name = action['report_name'] + + # Put the document name on the report filename + if 'context' in action: + # Try to get current object model and their ids from context + 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'): + # We put the template name in first + item_names.insert(0, action['name']) + # The filename will be "Template name - Document name" + file_name = ' - '.join(item_names) + # Create safe filename, replace special chars with _ + p = re.compile('[/:(")<>|?*]|(\\\)') + file_name = p.sub('_', file_name) + file_name = '%s.%s' % (file_name, report_struct['format']) return req.make_response(report,