Search code examples
pythonxmlodooqwebodoo-14

Odoo 14 Picking Operations report sort by location name


Im having issues in sorting the Qweb report by stock location names.

I have checked the default report and i cant figure out why it should not be sorted in the first place.

<t t-foreach="move.move_line_ids.sorted(key=lambda ml: ml.location_id.name, reverse=False)"
t-as="ml">

The list is still returned in the default order.

This is the Odoo standard report code:

<t t-foreach="o.move_ids_without_package" t-as="move">
<!-- In case you come across duplicated lines, ask NIM or LAP -->
<t t-foreach="move.move_line_ids.sorted(key=lambda ml: ml.location_id.id)" t-as="ml">

Even when printing the Odoo default report i get the order wrong.

What am i doing wrong?


Solution

  • the problem is that you are sorting move_line_ids from a stock.move, so unless there are several lines for that move, there's only one line to sort. To sort the whole picking by locations you should do it in the first <t>, like this:

    <t t-foreach="o.mapped('move_ids_without_package.move_line_ids').sorted(key=lambda ml: ml.location_id.id)" t-as="move">
    <t t-foreach="move" t-as="ml">