Odoo Help


PDF filename is always 'account.report_invoice' in ODOO 8

Juan Muñoz
on 7/28/15, 7:04 AM 2,610 views

Hi all, 

I'm trying to change code from /addons/web/controllers/main.py

(line: file_name = '%s.%s' % (file_name, report_struct['format'])

and also trying to edit code from /addons/account/account_report.xml

(<report> tags, lines: name="Invoice" file="account.report_invoice")

BUT nothing. The generated pdf name is always the same.

I install the module 'report_custom_filename' and in the invoice reports i set 'Download filename' to (object.number)+'.pdf' just to prove.

BUT NOTHING!! All what i see gloogling is useless. Only solutions to old versions of OpenERP.

Please if anyone knows how to solve this, help me with Odoo8 :( 

Thanks so much in advance.





| 6 5 7
Tbilisi, Georgia
On 7/28/15, 8:00 AM

try following:

do not change anything in original source code, then:

1. go to "Settings/Technical/Actions/Reports" page

2. find an action record that generates the PDF you're interested in.

3. As you find correct record, change it's "Save as Attachment Prefix" field as you like. 


- above solution applies to pdf attachment that's saved in the database but does not apply for the pdf you download immediately after click on "Print" button in the invoice form. As it's noted in comments, you can download this invoice pdf with a preconfigured name from attachments.

What it concerns name of file that's immediately downloaded after click on the "Print" button in invoice form, most probably it requires customization.

- Python tip (take look of report's controller):

### fseudo import: import report as re 
### see: how-to-import-odoo-module-in-another-module

class ReportController(re.controllers.main.ReportController):

def report_download(self, data, token):
response = super(ReportController, self).report_download(data,token) file_download_name = "Whatever you like" if "you have to handle this case(response != None, request type == 'qweb-pdf' etc...)": response.headers.set('Content-Disposition', 'attachment; filename=%s.pdf;' % file_download_name)
return response

this will cause downloaded file to have name: "Whatever you like.pdf"

actually it's not a complete solution, of course you'll need to somehow generate meaningful filename (the variable file_download_name in the code above), also it's possible that there is better place for this kind of intervention than report_download function...  good luck

Hi Temur, thanks for your reply. I've already tried. I have this: ((object.partner_id)['name'])+'_'+(object.number)+'_'+((object.date_invoice).split('-')[1])+'.pdf' But this field only generates the attachment file stored in Settings/Database/Attachments. I want the first time you click 'Print', the generated PDF file has a name that I want. I know i can go to Settings/Database/Attachments and download the generated file with the correct name, but what I want is possible? Thanks Temur.

Juan Muñoz
on 7/29/15, 3:18 AM

I'm afraid to disappoint you, but AFAIK that's not possible through configuration...

on 7/30/15, 2:51 AM

And through .py files? I glooged about it but i only see solutions to OpenERP7 or v6.1. If anyone have the same issue pls report here.

Juan Muñoz
on 7/30/15, 5:05 AM

And through .py files? I glooged about it but i only see solutions to OpenERP7 or v6.1. If anyone have the same issue pls report here.

Juan Muñoz
on 7/30/15, 5:05 AM

yes, through customisation it should be possible.. you tried to get worked the "report_custom_filename" module that you mention in the question?

on 7/30/15, 6:20 AM

Yes. I installed it and changed the 'Download filename' field in Settings/ Reports/ Invoices, and nothing. Later also i go to /addons/report_custom_filename/controllers/reports.py and modified some lines. Because i read that this module only runs with old report actions (ir.actions.report.xml), so i added a condition -> elif(http.request.session.model('ir.actions.act_window')): #the other action type. But nothitng :(

Juan Muñoz
on 7/30/15, 6:39 AM

updated answer with a python tip

on 7/30/15, 7:53 AM
On 7/19/16, 6:25 PM

I just found an OCA module that does that for all reports.


You need to download all the project here :


and don't forget to choose your Odoo version from repository branch.

On 2/22/16, 4:31 AM

Here you go:

# -*- coding: utf-8 -*-

from openerp.addons.report.controllers.main import ReportController
from openerp.http import request, route

import simplejson

class Main(ReportController):

    def get_custom_filename(self, model, res_id):
        """Default behavior will be to get the name of the generated attachment.
        If no attachment is found, for watever reason, this method will generate 
        the filename based on the res_model.
        Feel free to override it if needed.
        args = [('res_model', '=', model), ('res_id', '=', res_id)]
        attachment = request.env['ir.attachment'].search(args)

        if attachment.exists():
            return attachment.name

        record = request.env[res_model].browse(res_id)
        if record.exists():
            return '{}-{}'.format(record._table, record.name)

    def report_download(self, data, token):
        """Attempt to generate proper filenames for qweb-pdf."""
        res = super(Main, self).report_download(data, token)
        data = simplejson.loads(data)
        url, report_type = data

        if report_type != 'qweb-pdf':
            return res

        report_name, res_id = url.split('/report/pdf/')[1].split('/')
        args = [('report_name', '=', report_name)]
        act_report = request.env['ir.actions.report.xml'].search(args)
        if not act_report.exists():
            return res

        filename = self.get_custom_filename(act_report.model, int(res_id))
        if not(filename):
            return res

        if not filename.endswith('.pdf'):
            filename = '{}.pdf'.format(filename)

        content_disposition = 'attachment; filename={}'.format(filename)
        res.headers.set('Content-Disposition', content_disposition)

        return res

Just put that in a module python file and install it.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/28/15, 7:04 AM
Seen: 2610 times
Last updated: 7/19/16, 6:28 PM