【发布时间】:2018-11-15 08:27:37
【问题描述】:
odoo 10 报告...问题... 为什么 get_qty 不能向 docargs 发送数据? 我想要行数据...数量总和...按 product_id 相同... 为什么 xml t-foreach="data" 可以为我获取任何数据
class ReportStockInventorySummary(models.AbstractModel):
_name = 'report.stock.inventory.summary'
def get_qty(self, docids):
docs = self.env["stock.inventory"].browse(docids)
lines = self.env["stock.inventory.line"].search([('inventory_id', '=', docs.id)])
data = list()
show_data = list()
for x in lines:
data.append({
"line_location_id": x.location_id,
"line_product_id": x.product_id,
"line_product_qty": x.product_qty,
})
for i, g in groupby(sorted(data), key=lambda x: x['line_product_id']):
show_data.append([i, sum(v['line_product_qty'] for v in g)])
@api.multi
def render_html(self, docids, data):
report = self.env['report']
self.model = self.env.context.get('active_model')
docs = self.env["stock.inventory"].browse(docids)
docargs = {
'doc_ids': docids,
'doc_model': self.model,
'docs': docs,
'data': self.get_qty //* i want sum product_qty by product_id *//
}
return report.render("stock_inventory_report.report_stock_inventory_template", docargs)
<?xml version="1.0"?>
<odoo>
<data>
<template id="report_stock_inventory_template">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<div class="page">
<h2>Report title</h2>
<p>This object's name is
<span t-field="o.name"/>
</p>
<table class="table table-condensed">
<thead>
<tr>
<th><strong>Location</strong></th>
<th><strong>Product</strong></th>
<th class="text-right"><strong>Quantity</strong></th>
</tr>
</thead>
<!---- why t-foreach="data" cant show any data for me -->
<tr t-foreach="data" t-as="line">
<td><span t-esc="line['line_location_id']" /></td>
<td><span t-esc="line['line_product_id']" /></td>
<td><span t-esc="line['line_product_qty']" /></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</div>
</t>
</t>
</template>
</data>
</odoo>
我想从 qweb 中的 stock.inventory.lines 显示数据和字段(location_id、product_id、product_qty)我需要在上面的 py 中更改什么以及如何创建视图? 初学者有类似的例子吗?
【问题讨论】: