Reputation: 2358
I want sort data in my qweb report by date asc.
My example:
<t t-foreach="doc.line_ids" t-as="o">
<tr>
<td class="text-right">
<span t-field="o.date"/>
</td>
</tr>
</t>
Upvotes: 3
Views: 6593
Reputation: 2358
I've solved the problem with following code:
<t t-foreach="doc.line_ids.sorted(key=lambda x: x.date)" t-as="o">
<tr>
<td class="text-right">
<span t-field="o.date"/>
</td>
</tr>
</t>
Upvotes: 4
Reputation: 972
Hello user_odoo,
sorted()
returns a recordset sorted by the provided key function. If no key is provided, use the model's default sort order:
#sort records by name
records.sorted(key=lambda r: r.name)
sorted(key=None, reverse=False)
Return the recordset self ordered by key.
Parameters
key -- either a function of one argument that returns a comparison key for each record, or None, in which case records are ordered according the default model's order
reverse -- if True, return the result in reverse order
Your problem solution is below code try,
<tr t-foreach="doc.order_line.sorted(key=lambda record: record.name, reverse=False)" t-as="ol">
<td class="text-right">
<span t-field="ol.name"/>
</td>
...
</tr>
I hope my answer is helpful.
If any query so comments, Please.
Upvotes: 3