在 Odoo 中尝试 运行 mako 模板时出现 Jinja 错误
Jinja error when try to run mako template in Odoo
当我尝试 运行 这个用 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
从 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)}
当我尝试 运行 这个用 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
从 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)}