odoo 10 report...question ... why get_qty can't send data to docargs? i want lines data...qty sum...by product_id is same... why xml t-foreach="data" can get any data for me
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>
I want from stock.inventory.lines in qweb display data and field (location_id, product_id, product_qty) what do I need to change in above py and how do I create view? Any similar examples for a beginner?