Browse Source
Merge pull request #11 from akretion/7.0-backport-report_custom_filename
Merge pull request #11 from akretion/7.0-backport-report_custom_filename
7.0 backport report custom filenamepull/15/head
beau sebastien
10 years ago
9 changed files with 289 additions and 0 deletions
-
22report_custom_filename/__init__.py
-
87report_custom_filename/__openerp__.py
-
21report_custom_filename/controllers/__init__.py
-
53report_custom_filename/controllers/reports.py
-
34report_custom_filename/i18n/report_custom_filename.pot
-
21report_custom_filename/model/__init__.py
-
37report_custom_filename/model/ir_actions_report_xml.py
-
BINreport_custom_filename/static/src/img/icon.png
-
14report_custom_filename/view/ir_actions_report_xml.xml
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import controllers |
|||
from . import model |
@ -0,0 +1,87 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
{ |
|||
"name": "Custom report filenames", |
|||
"summary": "Configure the filename to use when downloading a report", |
|||
"version": "1.0", |
|||
"author": "Therp BV,Odoo Community Association (OCA)", |
|||
"license": "AGPL-3", |
|||
"complexity": "normal", |
|||
"category": "Reporting", |
|||
"description": """ |
|||
Custom report filenames |
|||
======================= |
|||
|
|||
This addon allows for custom filenames for reports. |
|||
|
|||
Configuration |
|||
============= |
|||
|
|||
To configure this module, open the report whose filename you want to change and fill in the `Download filename` field. This field is evaluated as jinja2 template with `objects` being a list of browse records of the records to print, and `o` the first record. |
|||
|
|||
Known issues / Roadmap |
|||
====================== |
|||
|
|||
* Currently, only old-style reports (ir.actions.report.xml) are supported, it should be simple to add support for qweb reports. |
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Holger Brunn <hbrunn@therp.nl> |
|||
* Sébastien Beau <sebastien.beau@akretion.com> |
|||
|
|||
Icon |
|||
---- |
|||
|
|||
Icon courtesy of http://www.picol.org/ (download_settings.svg) |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: http://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: http://odoo-community.org |
|||
|
|||
This module is maintained by the OCA. |
|||
|
|||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. |
|||
|
|||
To contribute to this module, please visit http://odoo-community.org. |
|||
""", |
|||
"depends": [ |
|||
'web', |
|||
'email_template', |
|||
], |
|||
"data": [ |
|||
"view/ir_actions_report_xml.xml", |
|||
], |
|||
"test": [ |
|||
], |
|||
"auto_install": False, |
|||
"installable": True, |
|||
"application": False, |
|||
"external_dependencies": { |
|||
'python': ['jinja2'], |
|||
}, |
|||
} |
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import reports |
@ -0,0 +1,53 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
import simplejson |
|||
from openerp.addons.web import http |
|||
from openerp.addons.web.controllers import main |
|||
from openerp.addons.email_template import email_template |
|||
|
|||
|
|||
class Reports(main.Reports): |
|||
|
|||
@http.httprequest |
|||
def index(self, req, action, token): |
|||
result = super(Reports, self).index(req, action, token) |
|||
action = simplejson.loads(action) |
|||
context = dict(req.context) |
|||
context.update(action["context"]) |
|||
report_xml = req.session.model('ir.actions.report.xml') |
|||
report_ids = report_xml.search( |
|||
[('report_name', '=', action['report_name'])], |
|||
0, False, False, context) |
|||
for report in report_xml.read(report_ids, fields=['download_filename']): |
|||
if not report['download_filename']: |
|||
continue |
|||
objects = req.session.model(context['active_model'])\ |
|||
.browse(context['active_ids']) |
|||
generated_filename = email_template.mako_template_env\ |
|||
.from_string(report['download_filename'])\ |
|||
.render({ |
|||
'objects': objects, |
|||
'o': objects[0], |
|||
'object': objects[0], |
|||
}) |
|||
result.headers['Content-Disposition'] = main.content_disposition( |
|||
generated_filename, req) |
|||
return result |
@ -0,0 +1,34 @@ |
|||
# Translation of Odoo Server. |
|||
# This file contains the translation of the following modules: |
|||
# * report_custom_filename |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: Odoo Server 8.0\n" |
|||
"Report-Msgid-Bugs-To: \n" |
|||
"POT-Creation-Date: 2014-12-19 12:17+0000\n" |
|||
"PO-Revision-Date: 2014-12-19 12:17+0000\n" |
|||
"Last-Translator: <>\n" |
|||
"Language-Team: \n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=UTF-8\n" |
|||
"Content-Transfer-Encoding: \n" |
|||
"Plural-Forms: \n" |
|||
|
|||
#. module: report_custom_filename |
|||
#: field:ir.actions.report.xml,download_filename:0 |
|||
msgid "Download filename" |
|||
msgstr "" |
|||
|
|||
#. module: report_custom_filename |
|||
#: help:ir.actions.report.xml,download_filename:0 |
|||
msgid "Fill in this field to have a custom file name when downloading this report. This string is evaluated as a jinja2 expression.\n" |
|||
"You can use python expressions, `objects` is a browse record list of the objects for which the report is being generated.\n" |
|||
"Check for this list's length to determine if it is a report being printed for multiple records or not. You also have access to `o`, which is the first record in the list" |
|||
msgstr "" |
|||
|
|||
#. module: report_custom_filename |
|||
#: model:ir.model,name:report_custom_filename.model_ir_actions_report_xml |
|||
msgid "ir.actions.report.xml" |
|||
msgstr "" |
|||
|
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import ir_actions_report_xml |
@ -0,0 +1,37 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from openerp.osv import fields, orm |
|||
|
|||
|
|||
class IrActionsReportXml(orm.Model): |
|||
_inherit = 'ir.actions.report.xml' |
|||
|
|||
_columns = { |
|||
'download_filename': fields.char( |
|||
'Download filename', |
|||
help='Fill in this field to have a custom file name when ' |
|||
'downloading this report. This string is evaluated as a jinja2 ' |
|||
'expression.\nYou can use python expressions, `objects` is a ' |
|||
'browse record list of the objects for which the report is being ' |
|||
'generated.\nCheck for this list\'s length to determine if it is ' |
|||
'a report being printed for multiple records or not. You also ' |
|||
'have access to `o`, which is the first record in the list') |
|||
} |
After Width: 100 | Height: 100 | Size: 1.8 KiB |
@ -0,0 +1,14 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp> |
|||
<data> |
|||
<record id="act_report_xml_view" model="ir.ui.view"> |
|||
<field name="model">ir.actions.report.xml</field> |
|||
<field name="inherit_id" ref="base.act_report_xml_view" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="attachment" position="after"> |
|||
<field name="download_filename" /> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue