Skip to content

Commit

Permalink
[IMP] web: Make filename for print download dependent on object name.
Browse files Browse the repository at this point in the history
  • Loading branch information
NL66278 authored and Stefan Rijnhart committed Jul 2, 2014
1 parent 6a22419 commit 4d2ce45
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions addons/web/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,16 +1751,24 @@ def index(self, req, action, token):
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=[
Expand Down

3 comments on commit 4d2ce45

@ploegvde
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, when i select multiple records from a tree and so a print (e.q. invoices). Every name of all the selected records will be in the PDF file name. Is this the way this change was intended?

@pedrobaeza
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed on #18, that I have just merged.

@ploegvde
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's lightning fast! Thanks for the update.

Please sign in to comment.