【问题标题】:Jinja error when try to run mako template in Odoo尝试在 Odoo 中运行 mako 模板时出现 Jinja 错误
【发布时间】:2016-10-07 03:15:57
【问题描述】:

当我尝试运行这个用 mako 模板编写的报告时出现此错误:

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>

在 openerp 7 中运行良好,但在 odoo 8 中无法运行。

                <% 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

【问题讨论】:

    标签: openerp jinja2 odoo-8 openerp-7 mako


    【解决方案1】:

    从 Odoo V8 开始,您需要更改使用的语法,而使用 jinja2 似乎很难做到这一点。下面是在 Odoo V9 中使用销售订单测试的示例:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-24
      • 2016-05-18
      • 1970-01-01
      • 2020-12-01
      • 1970-01-01
      • 2022-12-29
      • 1970-01-01
      • 2013-09-17
      相关资源
      最近更新 更多