From f110fccf44f0581e359cddd03783521f9b3967f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 3 Sep 2017 11:14:10 +0200 Subject: [PATCH] Add support for single record report A single report render each record separately and return them in a zip file. To ensure the uniqueness of the file in the zip, it uses the id of the record but also the record name to be user-friendly. issue6640 review37581002 --- CHANGELOG | 1 + doc/topics/reports/index.rst | 16 ++++++++------ trytond/ir/action.py | 6 ++++++ trytond/ir/view/action_report_form.xml | 2 ++ trytond/report/report.py | 30 ++++++++++++++++++++------ 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 06f9f3595c..f1006bb317 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add support for single record report * Add support for Flat OpenDocument * Add get_email in trytond.report * Replace plain extension by txt diff --git a/doc/topics/reports/index.rst b/doc/topics/reports/index.rst index ab7bbf8bb2..d389af2185 100644 --- a/doc/topics/reports/index.rst +++ b/doc/topics/reports/index.rst @@ -50,6 +50,10 @@ When defining an `ir.action.report` the following attributes are available: * ``template_extension``: The template format. + * ``single``: `True` if the template works only for one record. If such + report is called with more than one record, a zip file containing all the + reports will be generated. + Report Usage ============ @@ -129,12 +133,12 @@ Accessing models from within the report --------------------------------------- By default instances of the models the report is for are passed in to the -report via a list of objects called `objects`. These objects behave just as -they would within trytond itself. You can access any of the models relations as -well. For example within the invoice report each object is an invoice and you -can access the name of the party of the invoice via `invoice.party.name`. -Additional objects can be passed to a report. This is discussed below in -`Passing custom data to a report`. +report via a list of objects called `records` (or `record` if `single` is +`True`). These records behave just as they would within trytond itself. You +can access any of the models relations as well. For example within the invoice +report each object is an invoice and you can access the name of the party of +the invoice via `invoice.party.name`. Additional objects can be passed to a +report. This is discussed below in `Passing custom data to a report`. Within Tryton the underlying model the report can be found by following the Menu to ``Administration > UI > Actions > Report``. Furthermore in tryton the diff --git a/trytond/ir/action.py b/trytond/ir/action.py index c04f666b1b..fd82b940c7 100644 --- a/trytond/ir/action.py +++ b/trytond/ir/action.py @@ -409,6 +409,8 @@ class ActionReport(ActionMixin, ModelSQL, ModelView): action = fields.Many2One('ir.action', 'Action', required=True, ondelete='CASCADE') direct_print = fields.Boolean('Direct Print') + single = fields.Boolean("Single", + help="Check if the template works only for one record.") template_extension = fields.Selection([ ('odt', 'OpenDocument Text'), ('odp', 'OpenDocument Presentation'), @@ -582,6 +584,10 @@ class ActionReport(ActionMixin, ModelSQL, ModelView): def default_direct_print(): return False + @classmethod + def default_single(cls): + return False + @staticmethod def default_template_extension(): return 'odt' diff --git a/trytond/ir/view/action_report_form.xml b/trytond/ir/view/action_report_form.xml index ac77fd5c15..de9363cc6f 100644 --- a/trytond/ir/view/action_report_form.xml +++ b/trytond/ir/view/action_report_form.xml @@ -23,6 +23,8 @@ this repository contains the full copyright notices and license terms. -->