odoo 10 自定义报告..sum lines qty..by product_id
odoo 10 custom report ..sum lines qty..by product_id
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>
我想从stock.inventory.lines在qweb中显示数据和字段(location_id,product_id,product_qty)我需要在上面的py中更改什么以及如何做我创建视图?
初学者有没有类似的例子?
您正在将方法 get_qty
绑定到 data
,但您应该改为调用它。
'data': self.get_qty(doc_ids)
最好不要使用data
键,因为它已经被另一个进程使用了。只需制作您自己的密钥并在您的报告模板中使用它而不是数据:
'get_qty': self.get_qty(doc_ids)
而且您的方法没有 returning 任何响应。 None
。我认为 show_data
是你的 return 结果所以只是 return 它。
def get_qty(self, docids):
show_data = []
# ...
return show_data
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>
我想从stock.inventory.lines在qweb中显示数据和字段(location_id,product_id,product_qty)我需要在上面的py中更改什么以及如何做我创建视图? 初学者有没有类似的例子?
您正在将方法 get_qty
绑定到 data
,但您应该改为调用它。
'data': self.get_qty(doc_ids)
最好不要使用data
键,因为它已经被另一个进程使用了。只需制作您自己的密钥并在您的报告模板中使用它而不是数据:
'get_qty': self.get_qty(doc_ids)
而且您的方法没有 returning 任何响应。 None
。我认为 show_data
是你的 return 结果所以只是 return 它。
def get_qty(self, docids):
show_data = []
# ...
return show_data