Skip to content
Snippets Groups Projects
Commit da3d2fb1 authored by Mohammed Shekha's avatar Mohammed Shekha Committed by Yannick Tivisse
Browse files

[IMP] report: Printed Report names customization

PURPOSE
=======

I've seen this new improvement regarding the naming of the printed reports:
https://www.odoo.com/web?#id=10870&view_type=form&model=project.task&menu_id=3942&action=327

This makes the report have the pdf name being the name instead of the report_name of
the ir.actions.report.xml, which is already an improvement.

But why don't we allow the users to have their own naming conventions?
I mean, we could allow our client to create and name their pdf the way they want, as
they do regarding the attachment.

Not only when it's about saving it as an attachment on the record, but also when downloading
directly the pdf, such that the modification in the previous screenshot, would give the following
result when downloaded:

People need to have their pdf named automatically according to a convention. When you print 10 sales
order during an hour, you don't want to get lost in having the following:
Devis / Commande.pdf
Devis / Commande(1).pdf
Devis / Commande(2).pdf
Devis / Commande(3).pdf
Devis / Commande(4).pdf
Devis / Commande(5).pdf
Devis / Commande(6).pdf
Devis / Commande(7).pdf

especially when those are for different partners.
parent 0b52d097
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ Report
'data/report_paperformat.xml',
'security/ir.model.access.csv',
'views/report.xml',
'views/ir_actions.xml',
],
'installable': True,
'auto_install': True,
......
......@@ -4,8 +4,10 @@
from openerp.addons.web.http import Controller, route, request
from openerp.addons.web.controllers.main import _serialize_exception, content_disposition
from openerp.tools import html_escape
from openerp.tools.safe_eval import safe_eval as eval
import json
import time
from werkzeug import exceptions, url_decode
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
......@@ -102,6 +104,10 @@ class ReportController(Controller):
cr, uid = request.cr, request.uid
report = request.registry['report']._get_report_from_name(cr, uid, reportname)
filename = "%s.%s" % (report.name, "pdf")
ids = [int(x) for x in docids.split(",")]
obj = request.env[report.model].browse(ids)
if report.print_report_name and not len(obj) > 1:
filename = eval(report.print_report_name, {'object': obj, 'time': time})
response.headers.add('Content-Disposition', content_disposition(filename))
response.set_cookie('fileToken', token)
return response
......
import abstract_report
import ir_actions
import report
import report_paperformat
import abstract_report
......
from openerp import models, fields
class Actions(models.Model):
_inherit = 'ir.actions.report.xml'
print_report_name = fields.Char('Printed Report Name', help="This is the filename of the report going to download. Keep empty to not change the report filename. You can use a python expression with the object and time variables.")
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Adding a print_report_name field inside to the report action form view -->
<record id="act_report_xml_view_inherit_report" model="ir.ui.view">
<field name="name">ir.actions.report.xml.form.inherit</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="model">ir.actions.report.xml</field>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='report_name']" position="after">
<field name="print_report_name" />
</xpath>
</data>
</field>
</record>
</data>
</openerp>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment