Skip to content Skip to sidebar Skip to footer

Odoo Qweb Report Lines In Alphabetical Order

I'm getting crazy for what I believe it is a really silly matter. I need to render the result of an array in alphabetical order:

Solution 1:

Have a look at this

You could set a new variable to order_line.sorted() and then iterate on the new variable

For sorting have a look at Odoo reference

Solution 2:

I have just faced this problem and I was able to solve it with sorted function, as @Alessandro Ruffolo wrote. You have to pass the right parameters to that function, in your case it would be:

<trt-foreach="o.order_line.sorted(key=lambda r: r.name, reverse=True)"t-as="l"><td><spant-field="l.name"/></td>
    ...
</tr>

Solution 3:

Actually you cannot use ".sort()" for one main reason:

  • ".sort()" on a list sorts the list in place, returning None

The best you can do is to use sorted, which does not modify the iterable you pass to it but returns its sorted value. Like this:

 <tr t-foreach="sorted(o.order_line, key=lambda x: x.get('A_FIELD_TO_SORT_UPON')" t-as="l"> 

The key could be any fuction that returns the value to be used for sorting.

See some more examples on sorted usage here.

Solution 4:

If you want to sort item in Odoo Report this is will work!!!

<tr t-foreach="get_room_used_detail(data['form']['date_start'],data['form']['date_end']).sorted(key=lambda x: x.checkin)" t-as="info">

Post a Comment for "Odoo Qweb Report Lines In Alphabetical Order"