Report

A report generates printable documents from ModelStorage records.

There is also a more practical introduction into reports.

class trytond.report.Report

This is the base class for all reports.

Class attributes are:

Report.__name__

The unique name used to reference the report throughout the platform.

Class methods are:

classmethod Report.__setup__()

Setup the class before adding it to the Pool.

classmethod Report.__post_setup__()

Setup the class after adding it to the Pool.

classmethod Report.__register__(module_name)

Registers the report.

classmethod Report.check_access(action, model, ids)

Verifies if the user is allowed to execute the report.

classmethod Report.header_key(record[, data])

Returns a tuple of keys, composed of couples of name and record value, used to group document with the same header. data is the dictionary passed to :meth:~Report.execute`.

classmethod Report.execute(ids, data)

Executes the report for the ModelStorage instances with the ids and returns a tuple containing the report type, the content, a boolean to indicate direct printing and the report name. data is a dictionary that will be available in the evaluation context of the report.

classmethod Report.get_context(records, header, data)

Returns a dictionary with the evaluation context of the report template. The context is filled by default with the keys:

classmethod Report.render(report, report_context)

Returns the content of the Report <model-ir.action.report> rendered by the templating engine. And add gettext and ngettext to the evaluation context for translatable reports.

classmethod Report.convert(report, data[, timeout[, retry]])

Converts the report content data into the format defined by the Report <model-ir.action.report>.

classmethod Report.format_date(value[, lang[, format]])

Returns the formatted date.

classmethod Report.format_datetime(value[, lang[, format[, timezone]]])

Returns the formatted datetime.

classmethod Report.format_timedelta(value[, converter[, lang]])

Returns the formatted timedelta.

classmethod Report.format_currency(value, lang, currency[, symbol[, grouping[, digits]]])

Returns the formatted numeric value.

classmethod Report.format_number(value, lang[, digits[, grouping[, monetary]]])

Returns the formatted numeric value.

classmethod Report.format_number_symbol(value, lang, symbol[, digits[, grouping[, monetary]]])

Returns the numeric value formatted using the SymbolMixin instance.

classmethod Report.barcode(name, code[, size[, \*\*kwargs]])

Returns named barcode image for the code, the mimetype and the size. The optional keyword arguments are the same as generate_svg().

classmethod Report.qrcode(code[, size[, \*\*kwargs]])

Returns the QRCode image for the code, the mimetype and the size. The optional keyword arguments are the sames as generate_svg().

Email

Email reports must have HTML as output format. MJML syntax can be used with the XML input format and HTML output format to generate responsive emails.

trytond.report.get_email(report, record, languages)

Returns the EmailMessage and title using the Report <model-ir.action.report> rendered for the ModelStorage record for each language.

Note

Order languages with the preferred last.

trytond.report.mjml_to_html(content)

Converts MJML content to HTML.

Warning

It may return the content unconverted if some dependencies are missing.

html_to_text(content):

Converts HTML content to plain text.

Warning

It may return None if some dependencies are missing.