Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2922 Lượt xem

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: 

                                                

                                  


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 24
1578
2
thg 7 24
3070
2
thg 4 24
2883
2
thg 5 21
7384
4
thg 10 20
5806