In odoo13 i have a python function like this
def get_data(self, params):
json_string = [{"SKU": "A4110","Unit": "PC"}]
return json_string
and file xml view like this
<record id="view_report_product_qweb" model="ir.ui.view">
<field name="name">report.view.qweb</field>
<field name="model">view.product</field>
<field name="mode">primary</field>
<field name="arch" type="xml">
<qweb>
<div id="pivot-container1"></div>
<script>
new WebDataRocks({
"container": "#pivot-container1",
"width": "100%",
"height": 430,
"toolbar": true,
"report": {
"dataSource": {
"type": "json", "data": json_string
},
"slice": {
"rows": [{"uniqueName": "Product"}],
"columns": [{"uniqueName": "[Measures]"}],
"measures": [{"uniqueName": "Quantity", "aggregation": "sum"}]
}
}
});
</script>
</qweb>
</field>
</record>
how i get data from function push to xml view to render webdatarock excel
You can achieve this with two approaches at least that I know of:
Step 1:
You create a class inheriting from odoo's
Abstract modeland give it a name with the given exact notation.The template name stands for the actual
template_idand not thereport_id. The function has to be defined as it is with the@api.model decorationin place.The function then returns the data you computed and will be passed to the template above.
The returned object can be accessed as it is in the template that is something like
<t t-foreach="some_variable" as "o"> ...Check this link for official docs qweb
Step 2: The example below is from an answer in odoo forum at here
The return statement should be like this: arguments passed in the
report_action(args)are the data you want to access from the qweb.return self.env.ref('module_name.report_definition_id').report_action(employees, data=datas)Notice the
report_definition_idand not thetemplate_id