qweb 报告中的 Foreach xml Odoo 8
Foreach in qweb report xml Odoo 8
我想显示这样的数据:
No | Code | Brand | Cost
------------------------
1 | 201 | |
------------------------
| | A | 200
| | B | 350
------------------------
2 | 202 | |
------------------------
| | C | 100
| | D | 110
这是我在 py 中的代码 xml:
py 中的代码:
report=self.env['report']
document=self._get_pos_report_one(data)
docss=self._get_pos_report_two(data)
ctx=self._context.copy()
object=self.env['report.wizard'].browse([ctx['active_id']])
data={'o':object,
'docs':document,
'docss':docss}
return report.render('report.report_sales', data)
xml中的代码:
<tr t-foreach="docs" t-as="row" class="line_bottom line_top pb_font_10 text_bold">
<td class="pb_text_center line_left">
<t t-set="num" t-value="num + 1"/>
<t t-esc="num"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row['code']"/>
</td>
<tr t-foreach="docss" t-as="row_detail" class="pb_font_10">
<td class="pb_text_center line_left">
</td>
<td class="pb_text_left line_left">
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['brand']"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['cost']"/>
</td>
</tr>
</tr>
这是我的代码(py 和 xml)的当前结果:
No | Code | Brand | Cost
------------------------
1 | 201 | |
------------------------
| | A | 200
| | B | 350
| | C | 100
| | D | 110
------------------------
2 | 202 | |
------------------------
| | A | 200
| | B | 350
| | C | 100
| | D | 110
我试过代码
-文档(行['code'])
- docss.code 等等。
希望有人帮助我。
谢谢!
我已经解决了问题:
<tr t-foreach="docs" t-as="row" class="line_bottom line_top pb_font_10 text_bold">
<td class="pb_text_center line_left">
<t t-set="num" t-value="num + 1"/>
<t t-esc="num"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row['code']"/>
</td>
<tr t-foreach="docss" t-as="row_detail" class="pb_font_10">
<t t-if="row['code']==row_detail['code']">
<td class="pb_text_center line_left">
</td>
<td class="pb_text_left line_left">
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['brand']"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['cost']"/>
</td>
</t>
</tr>
我想显示这样的数据:
No | Code | Brand | Cost
------------------------
1 | 201 | |
------------------------
| | A | 200
| | B | 350
------------------------
2 | 202 | |
------------------------
| | C | 100
| | D | 110
这是我在 py 中的代码 xml:
py 中的代码:
report=self.env['report']
document=self._get_pos_report_one(data)
docss=self._get_pos_report_two(data)
ctx=self._context.copy()
object=self.env['report.wizard'].browse([ctx['active_id']])
data={'o':object,
'docs':document,
'docss':docss}
return report.render('report.report_sales', data)
xml中的代码:
<tr t-foreach="docs" t-as="row" class="line_bottom line_top pb_font_10 text_bold">
<td class="pb_text_center line_left">
<t t-set="num" t-value="num + 1"/>
<t t-esc="num"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row['code']"/>
</td>
<tr t-foreach="docss" t-as="row_detail" class="pb_font_10">
<td class="pb_text_center line_left">
</td>
<td class="pb_text_left line_left">
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['brand']"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['cost']"/>
</td>
</tr>
</tr>
这是我的代码(py 和 xml)的当前结果:
No | Code | Brand | Cost
------------------------
1 | 201 | |
------------------------
| | A | 200
| | B | 350
| | C | 100
| | D | 110
------------------------
2 | 202 | |
------------------------
| | A | 200
| | B | 350
| | C | 100
| | D | 110
我试过代码 -文档(行['code']) - docss.code 等等。
希望有人帮助我。 谢谢!
我已经解决了问题:
<tr t-foreach="docs" t-as="row" class="line_bottom line_top pb_font_10 text_bold">
<td class="pb_text_center line_left">
<t t-set="num" t-value="num + 1"/>
<t t-esc="num"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row['code']"/>
</td>
<tr t-foreach="docss" t-as="row_detail" class="pb_font_10">
<t t-if="row['code']==row_detail['code']">
<td class="pb_text_center line_left">
</td>
<td class="pb_text_left line_left">
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['brand']"/>
</td>
<td class="pb_text_left line_left">
<span t-esc="row_detail['cost']"/>
</td>
</t>
</tr>