report

7
Reports are written in HTML/QWeb, like all regular views in Odoo. You can use the usual QWeb control flow tools (qweb.html#reference-qweb). The PDF rendering itself is performed by wkhtmltopdf (http://wkhtmltopdf.org). If you want to create a report on a certain model, you will need to define this Report and the Report template it will use. If you wish, you can also specify a specific Paper Format for this report. Finally, if you need access to more than your model, you can define a Custom Reports class that gives you access to more models and records in the template. Report Every report must be declared by a report action (actions.html#reference-actions-report). For simplicity, a shortcut <report> element is available to define a report, rather than have to set up the action (actions.html#reference-actions-report) and its surroundings manually. That <report> can take the following attributes: id the generated record's external id (../glossary.html#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) QWeb Reports — odoo 8.0 documentation https://www.odoo.com/documentation/8.0/referen... 1 sur 7 05 09:06 ص2015 ﻳﻮن,

Upload: achrefo-mh

Post on 17-Dec-2015

14 views

Category:

Documents


0 download

DESCRIPTION

odoo

TRANSCRIPT

  • Reports are written in HTML/QWeb, like all regular views in

    Odoo. You can use the usual QWeb control flow tools

    (qweb.html#reference-qweb). The PDF rendering itself is

    performed by wkhtmltopdf (http://wkhtmltopdf.org).

    If you want to create a report on a certain model, you will need to define this Report and the Report

    template it will use. If you wish, you can also specify a specific Paper Format for this report. Finally, if you

    need access to more than your model, you can define a Custom Reports class that gives you access to

    more models and records in the template.

    ReportEvery report must be declared by a report action (actions.html#reference-actions-report).

    For simplicity, a shortcut element is available to define a report, rather than have to set up theaction (actions.html#reference-actions-report) and its surroundings manually. That cantake the following attributes:

    idthe generated record's external id (../glossary.html#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)

    QWeb Reports odoo 8.0 documentation https://www.odoo.com/documentation/8.0/referen...

    1 sur 7 05 09:06 2015 ,

  • the model your report will be about

    report_type (mandatory)either qweb-pdf for PDF reports or qweb-html for HTML

    report_namethe name of your report (which will be the name of the PDF output)

    groupsMany2many (orm.html#openerp.fields.Many2many) field to the groups allowed to view/use the

    current report

    attachment_useif 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)

    attachmentpython expression that defines the name of the report; the record is acessible as the variable

    object

    Example:

    WarningThe paper format cannot currently be declared via the shortcut, it must beadded afterwards using a extension on the report action itself:

    Report template

    QWeb Reports odoo 8.0 documentation https://www.odoo.com/documentation/8.0/referen...

    2 sur 7 05 09:06 2015 ,

  • Minimal viable templateA minimal template would look like:

    Calling external_layout will add the default header and footer on your report. The PDF body will be thecontent inside the . The template's id must be the name specified in the reportdeclaration; 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:

    docsrecords for the current report

    doc_idslist of ids for the docs records

    doc_modelmodel for the docs records

    timea reference to time (https://docs.python.org/2/library/time.html#module-time) from the Pythonstandard library

    translate_doc

    a function to translate a part of a report. It must be used as follow:

    userres.user record for the user printing the report

    res_companyrecord for the current user 's company

    Report titleThis object's name is

  • If you wish to access other records/models in the template, you will need a custom report.

    Translatable TemplatesIf you wish to translate reports (to the language of a partner, for example), you need to define two

    templates:

    The main report template

    The translatable document

    You can then call translate_doc from your main template to obtain the translated document. If you wish to

    see the details of the translation in the backend, you can go to Settings Reports Report Search associated QWeb views Associatedtranslations.

    For example, let's look at the Sale Order report from the Sale module:

    The main template calls translate_doc with partner_id.lang as a parameter, which means it uses acustom report model to access a res.partner record.

  • Barcodes are images returned by a controller and can easily be embedded in reports thanks to the QWeb

    syntax:

    More parameters can be passed as a query string

    Useful RemarksTwitter Bootstrap and FontAwesome classes can be used in your report template

    Local CSS can be put directly in the template

    Global CSS can be inserted in the main report layout by inheriting its template and inserting your CSS:

    .example-css-class { background-color: red; }

    Paper FormatPaper formats are records of report.paperformat and can contain the following attributes:

    name (mandatory)only useful as a mnemonic/description of the report when looking for one in a list of some sort

    descriptiona small description of your format

    formateither a predefined format (A0 to A9, B0 to B10, Legal, Letter, Tabloid,...) or custom ; A4 by default.You cannot use a non-custom format if you define the page dimensions.

    dpioutput DPI; 90 by default

    margin_top , margin_bottom , margin_left , margin_right

    QWeb Reports odoo 8.0 documentation https://www.odoo.com/documentation/8.0/referen...

    5 sur 7 05 09:06 2015 ,

  • margin sizes in mm

    page_height , page_widthpage dimensions in mm

    orientationLandscape or Portrait

    header_lineboolean to display a header line

    header_spacingheader spacing in mm

    Example:

    French Bank Check

    custom80175Portrait3333

    380

    Custom ReportsThe report model has a default get_html function that looks for a model namedreport.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 render_htmland pass objects in the docargs dictionnary:

    QWeb Reports odoo 8.0 documentation https://www.odoo.com/documentation/8.0/referen...

    6 sur 7 05 09:06 2015 ,

  • from openerp import api, models

    class ParticularReport(models.AbstractModel):_name = 'report.module.report_name'@api.multidef render_html(self, data=None):

    report_obj = self.env['report']report = report_obj._get_report_from_name('module.report_name')docargs = {

    'doc_ids': self._ids,'doc_model': report.model,'docs': self,

    }return report_obj.render('module.report_name', docargs)

    Reports are web pagesReports are dynamically generated by the report module and can be accessed directly via URL:

    For example, you can access a Sale Order report in html mode by going to http:///report

    /html/sale.report_saleorder/38

    Or you can access the pdf version at http:///report/pdf/sale.report_saleorder/38

    QWeb Reports odoo 8.0 documentation https://www.odoo.com/documentation/8.0/referen...

    7 sur 7 05 09:06 2015 ,