Search code examples
odoojinja2odoo-8openerp-7mako

Jinja error when try to run mako template in Odoo


I got this error when I try to run this report which written in mako template:

Encountered unknown tag 'total_price'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.

<class 'jinja2.exceptions.TemplateSyntaxError'>,Encountered unknown tag 'total_price'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.,<traceback object at 0x02F2F490>

It was working fine in openerp 7 but in odoo 8 didn't work.

                <% total_price = 0.0 %>
                %for line_container_ids in shipping.container_line_ids:
                    <%
                        total_price = line_container_ids.product_qty * line_container_ids.net_price
                        curr = line_container_ids.currency_id.name
                    %>
                % endfor

Solution

  • Since Odoo V8 you need to change the used syntax and it seems it's very hard to do such things with jinja2. Here an example tested with an sales order in Odoo V9:

    % set total_price = []
    % for line in object.order_line:
        % if total_price.append(line.price_subtotal)
        % endif
    % endfor
    ${sum(total_price)}