跳至内容
菜单
此问题已终结
1 回复
2908 查看

I created report from wizard but when i iterate the variable sales in xml template file it appear as a string,  and when i iterate it in python it work correctly
This is the function of report:

def action_print_errors(self):
domain=[]
user=self.user
date_from=self.date_from
date_to=self.date_to
domain+=[('user_id','=',user.id)]
domain+=[('date_order','>=',date_from)]
domain+=[('date_order','<=',date_to)]
sales=self.env['sale.order'].search(domain)
print(sales)
for sale in sales:
for line in sale["order_line"]:
print("product:",line.product_id.name)
data = {
'form': self.read()[0],
'sales': sales,

}
return self.env.ref('selling_errors.show_quotation_report').report_action(self,data=data)

This is code of iteration in xml report:

<tbody>
<t t-foreach="sales" t-as="o">
<t t-foreach="o['order_line']" t-as="line">
<span t-esc="line.product_id.name"/>
</t>
</t>
</tbody>


Why xml consider that sales variable is string not object? how can i solve it

despite it work correctly as an object in python file



This is the error  appears:

Error to render compiling AST
TypeError: string indices must be integers
Template: selling_errors.report_show_quotation
Path: /t/t/t/div/div/table/tbody/t/t
Node: 

                                                

                                  


形象
丢弃
最佳答案

Hi,

Please try like as follows:-

<tbody>
<t t-foreach="sales" t-as="o">
<t t-foreach="o.order_line" t-as="line">
<span t-esc="line.product_id.name"/>
</t>
</t>
</tbody>

Regards

形象
丢弃
相关帖文 回复 查看 活动
0
9月 24
1573
2
7月 24
3052
2
4月 24
2871
2
5月 21
7383
4
10月 20
5801