I'm doing some web programming to display the most sold 3 products and their value on a dashboard. I called a python function that returns a dictionary of calculated values to display, from the javascript file(using _rpc). The qweb is called from js file. Things seem to working but I cannot display the value in the key,value pair of the dictionary.
My python file
@api.model
def compute_dashboard(self):
order_line = self.env['sale.order.line'].search([('state', '=', 'sale')])
totals = {}
for record in order_line:
totals[record.product_id.name] = totals.get(record.product_id.name,0) + record.price_total
return_val['totals'] = totals
print(return_val)
return return_val
And my qweb file
<div class="col-sm-6 col-md-6">
<div class="col-sm-6 col-md-6 task_box" style="border-right:0">
<b>Top Sellers</b>
<t t-foreach="values.totals" t-as="pairs"> <!--displays product names, but not in desc order or limited by 3-->
<t t-esc="pairs"/><br/></t>
</div>
<div class="col-sm-6 col-md-6 task_box" style="border-left:0">
<b>Total</b>
<!--what to write here to display corresponding values-->>
</div>
</div>
The console.log() displays correct output
totals: {product 1: 420, product 2: 1165.52, product 3: 1547, product 4: 2000, product 5: 3200}
So my question is what to write in qweb, so as the products and values get displayed in the descending order of their values, limited by just top 3 products.(I only want top 3 products to be displayed)
Should I use lists instead of dictionaries?
Thanks in advance.