This is the documentation for older versions of Odoo (formerly OpenERP).

See the new Odoo user documentation.

See the new Odoo technical documentation.

Html Reports Using Mako Templates


Implemented in trunk only

Mako is a template library written in Python. It provides a familiar, non-XML syntax which compiles into Python modules for maximum performance.

Mako Template


A Mako template is parsed from a text stream containing any kind of content, XML, HTML, email text, etc.

The template can further contain Mako-specific directives which represent variable and/or expression substitutions, control structures (i.e. conditionals and loops), server-side comments, full blocks of Python code, as well as various tags that offer additional functionality. All of these constructs compile into real Python code.

This means that you can leverage the full power of Python in almost every aspect of a Mako template.

Expression Substitution

The simplest expression is just a variable substitution. The syntax for this is the ${} construct instead of [[ ]] in rml.


this is x: ${x}

    Above, the string representation of x is applied to the template's output stream where x comes from the localcontext supplied to the template's rendering function.

    The contents within the ${} tag are evaluated by Python directly.
Control Structures:

In Mako, control structures (i.e. if/else, loops (like while and for), as well as things like try/except) are written using the % marker followed by a regular Python control expression, and are "closed" by using another % marker with the tag "end<name>", where "<name>" is the keyword of the expression:


% if x==5:
  this is some output
% endif

Python Blocks

Within <% %>, you're writing a regular block of Python code. While the code can appear with an arbitrary level of preceding whitespace, it has to be consistently formatted with itself. Mako's compiler will adjust the block of Python to be consistent with the surrounding generated Python code.

Useful links:

An Overview of Sale Order Example

For Complete Example of Sale_order please Refer the module sale_report_html from :

## -*- coding: utf-8 -*-
        <%include file="mako_header.html"/>
% for o in objects:
    <table width="100" border="0" cellspacing="0" cellpadding="0">
                                <p><small><b>Shipping address :</b></small>
                                <small>${ o.partner_id.title or '' } ${ }</small>
                                <small>${ o.partner_shipping_id.state_id and or '' } ${ o.partner_shipping_id.country_id and or '' }</small>
                   <tr align="left">
                          <th>Unit Price</th>
                % for line in o.order_line:
                          <td>${', '.join(map(lambda x:, line.tax_id))}</td>
                          <td>${line.product_uos and line.product_uos_qty or line.product_uom_qty}
                          ${line.product_uos and or}</td>
                          <td>${ or 0.00 }</td>
                          <td>${line.price_subtotal or 0.00 }</td>
                  % if line['notes']:

                  % endif
                  % endfor
% endfor
<%include file="mako_footer.html"/>

You can format the report as you need using HTML.