diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-07-20 10:57:15 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2020-07-28 13:03:13 +0000 |
| commit | 96a3265118df686a0175b240c9636cfd2b53a492 (patch) | |
| tree | 26174a2c0e03106ac3d25989a8d67ec9a8319b43 /doc/reference/reports.rst | |
| parent | 48335c04bf8b96a9b8a80b222b58981515ec3ce7 (diff) | |
[FIX] doc: remove <act_window> and <report>
* remove <report> and <act_window> form the backend tutorial
* remove documentation for <report> in the report doc
Also various fixes and improvements:
* add ACL to the wizard in the tutorial, as transients now require ACLs
* fix indentation & spacing in rST
* reword a few bits
* improve styling of footnote references (and recompile stylesheet
with recent lessc which apparently changes its output formatting
quite a bit)
Diffstat (limited to 'doc/reference/reports.rst')
| -rw-r--r-- | doc/reference/reports.rst | 142 |
1 files changed, 57 insertions, 85 deletions
diff --git a/doc/reference/reports.rst b/doc/reference/reports.rst index 3de92214b9a..3b13b390dcb 100644 --- a/doc/reference/reports.rst +++ b/doc/reference/reports.rst @@ -4,83 +4,42 @@ .. _reference/reports: +.. _reference/reports/report: + ============ QWeb Reports ============ -Reports are written in HTML/QWeb, like all regular views in Odoo. You can use +Reports are written in HTML/QWeb, like website views in Odoo. You can use the usual :ref:`QWeb control flow tools <reference/qweb>`. The PDF rendering itself is performed by wkhtmltopdf_. -If you want to create a report on a certain model, you will need to define -this :ref:`reference/reports/report` and the -:ref:`reference/reports/templates` it will use. If you wish, you can also -specify a specific :ref:`reference/reports/paper_formats` for this -report. Finally, if you need access to more than your model, you can define a -:ref:`reference/reports/custom_reports` class that gives you access to more -models and records in the template. - -.. _reference/reports/report: - -Report -====== +Reports are declared using a :ref:`report action <reference/actions/report>`, +and a :ref:`reference/reports/templates` for the action to use. -Every report must be declared by a :ref:`report action -<reference/actions/report>`. - -For simplicity, a shortcut ``<report>`` element is available to define a -report, rather than have to set up :ref:`the action -<reference/actions/report>` and its surroundings manually. That ``<report>`` -can take the following attributes: - -``id`` - the generated record's :term:`external id` -``name`` (mandatory) - only useful as a mnemonic/description of the report when looking for one - in a list of some sort -``model`` (mandatory) - the model your report will be about -``report_type`` (mandatory) - either ``qweb-pdf`` for PDF reports or ``qweb-html`` for HTML -``file`` - The path to the main report file (depending on Report Type) - or empty if the content is in another field -``print_report_name`` - the name of your report (which will be the name of the PDF output) -``groups`` - :class:`~odoo.fields.Many2many` field to the groups allowed to view/use - the current report -``attachment_use`` - if set to True, the report will be stored as an attachment of the record - using the name generated by the ``attachment`` expression; you can use - this if you need your report to be generated only once (for legal reasons, - for example) -``attachment`` - python expression that defines the name of the report; the record is - acessible as the variable ``object`` -``paperformat`` - external id of the paperformat you wish to use (defaults to the company's - paperformat if not specified) - -Example:: - - <report - id="account_invoices" - model="account.invoice" - string="Invoices" - report_type="qweb-pdf" - name="account.report_invoice" - file="account.report_invoice" - attachment_use="True" - attachment="(object.state in ('open','paid')) and - ('INV'+(object.number or '').replace('/','')+'.pdf')" - /> +It useful or necessary, it is possible to specify a +:ref:`reference/reports/paper_formats` for the report report. .. _reference/reports/templates: Report template =============== +Report templates will always provide the following variables: + +``time`` + a reference to :mod:`python:time` from the Python standard library +``user`` + ``res.user`` record for the user printing the report +``res_company`` + record for the current ``user``'s company +``website`` + the current website object, if any (this item can be present but ``None``) +``wen_base_url`` + the base url for the webserver +``context_timestamp`` + a function taking :class:`python:datetime.datetime` in UTC\ [#unzoned]_ and + converting it to the timezone of the user printing the report Minimal viable template ----------------------- @@ -107,7 +66,7 @@ report declaration; for example ``account.report_invoice`` for the above report. Since this is a QWeb template, you can access all the fields of the ``docs`` objects received by the template. -There are some specific variables accessible in reports, mainly: +By default, the rendering context will also expose the following items: ``docs`` records for the current report @@ -115,15 +74,10 @@ There are some specific variables accessible in reports, mainly: list of ids for the ``docs`` records ``doc_model`` model for the ``docs`` records -``time`` - a reference to :mod:`python:time` from the Python standard library -``user`` - ``res.user`` record for the user printing the report -``res_company`` - record for the current ``user``'s company If you wish to access other records/models in the template, you will need -:ref:`a custom report <reference/reports/custom_reports>`. +:ref:`a custom report <reference/reports/custom_reports>`, however in that case +you will have to provide the items above if you need them. Translatable Templates ---------------------- @@ -226,6 +180,7 @@ Useful Remarks </t> </xpath> </template> + * If it appears that your PDF report is missing the styles, please check :ref:`these instructions <reference/backend/reporting/printed-reports/pdf-without-styles>`. @@ -282,12 +237,16 @@ Example:: Custom Reports ============== -The report model has a default ``get_html`` function that looks for a model -named :samp:`report.{module.report_name}`. If it exists, it will use it to -call the QWeb engine; otherwise a generic function will be used. If you wish -to customize your reports by including more things in the template (like -records of others models, for example), you can define this model, overwrite -the function ``_get_report_values`` and pass objects in the ``docargs`` dictionary: +By default, the reporting system builds rendering values based on the target +model specified through the ``model`` field. + +However, it will first look for a model named +:samp:`report.{module.report_name}` and call that model's +``_get_report_values(doc_ids, data)`` in order to prepare the rendering data for +the template. + +This can be used to include arbitrary items to use or display while rendering +the template, such as data from additional models: .. code-block:: python @@ -296,16 +255,24 @@ the function ``_get_report_values`` and pass objects in the ``docargs`` dictiona class ParticularReport(models.AbstractModel): _name = 'report.module.report_name' - @api.model def _get_report_values(self, docids, data=None): - report_obj = self.env['ir.actions.report'] - report = report_obj._get_report_from_name('module.report_name') - docargs = { - 'doc_ids': docids, - 'doc_model': report.model, - 'docs': self, + # get the report action back as we will need its data + report = self.env['ir.actions.report']._get_report_from_name('module.report_name') + # get the records selected for this rendering of the report + obj = self.env[report.model].browse(docids) + # return a custom rendering context + return { + 'lines': docids.get_lines() } - return docargs + +.. warning:: + + When using a custom report, the "default" document-related items + (``doc_ids``, ``doc_model`` and ``docs``) will *not* be included. If you + want them, you will need to include them yourself. + + In the example above, the rendering context will contain the "global" values + as well as the ``lines`` we put in there but nothing else. .. _reference/reports/custom_fonts: @@ -351,4 +318,9 @@ For example, you can access a Sale Order report in html mode by going to Or you can access the pdf version at \http://<server-address>/report/pdf/sale.report_saleorder/38 +.. [#unzoned] it does not matter what timezone the :class:`python:datetime` + object is actually in (including no timezone), its timezone will + unconditionally be *set* to UTC before being adjusted to the + user's + .. _wkhtmltopdf: https://wkhtmltopdf.org |
