I can't understand the behaviour of the Odoo API. It's driving me crazy.
As you may know, if you want to order a model by some of its fields, you have to modify the attribute _order
of the model. It works fine.
Now, suppose you want to order a specific view by some fields without altering the normal order of the model (this means: order a specific view by some fields and the rest of the views of the same model by other fields).
In this case, you have to use XML code, specifying the attribute default_order
in the kanban
or tree
tag, depending on which view you are modifying.
I've used this in the past succesfully. So I wanted to apply this again to a kanban view (this time I want to order by a boolean field, a char and another char).
Now my surprise: ordering by a boolean field reverses the order of the next fields if it values False
.
e.g. We have 6 records, which we want to order by a boolean, the name, and surname; in a kanban view with default_order
:
- True, John, Doe
- True, Jane, Doe
- True, John, Xoe
- False, John, Die
- False, Jane, Die
- False, Jane, Xie
So in the example, in the kanban view we'll see them ordered this way:
- True, Jane, Doe
- True, John, Doe
- True, John, Xoe
- False, John, Die
- False, Jane, Xie
- False, Jane, Die
As you can see, if the boolean values True
, the records are ordered by boolean, name and surname, which is what I want. But if it values False
, the records are ordered by boolean, name DESC, surname DESC.
What's going on? Did you experience the same? How can I order by a boolean, then a char, and then another char??
One method I use to to odd sortsis use the context to control it. In the window action for the kanban view, add a context like
and then on the model, override the search method, check for this flag in the context and set the sort order.