コンテンツへスキップ
メニュー
この質問にフラグが付けられました
4 返信
68787 ビュー

Hi,

 

Is there a way to change the default sorting column for a treeview (sales.order specifically)? I have a custom field I have set up and would like the sorting to default to this column.

 

Thanks all

アバター
破棄
最善の回答

VIA UI:

As of Odoo 8 you can simply add a default_order attribute in the view definition, to override the default ordering of the model. The syntax for this attribute is the same as the `_order` attribute of the model in Python.

Example:

<tree default_order='date_expected, picking_id, sequence'>
アバター
破棄

I tried this under the edit tree view - Manufacturing Orders (Edit Tree View (Developers Mode)) by adding the following line It now reads: It comes up with a ValidateError Field(s) `arch` failed against a constraint: Invalid view definition

Post a new question and expand 'I tried this' into steps with screenshots, so we can understand what you did and where you went wrong.

Working for four years with Odoo now and I never knew this. Thanks Ray, great tip! Upvoted.

@Ray : I tried this method and it is working perfectly for ascending order.Can you please tell how to do it in descinding order ?Thanks

Still works in Odoo 13

最善の回答

Hi,

in your class inherited of you module,

add :

class NameClass(....):

    _inherit = "name.class"

    _order = "custom_field_name, other_field ..." (you can add option asc or desc too)

Bye

アバター
破棄
著作者

Thanks for the prompt answer. I kind of hoped there was a GUI way of doing things since this is for just that one very very specific install, but I guess there isn't.

How can I give spesific order to tree view?? In your answer we must inherit class. Can we do it?

see https://www.odoo.com/forum/help-1/question/order-one2many-lines-29222#answer-75504

最善の回答

<tree default_order='date desc'> Does the trick for me.(For descinding order)

アバター
破棄
最善の回答

Instead of changing from the _order attribute from Python File.

You can just change the default_order attribute of Tree View (This way you can have different order by based on each tree view for that specific model)

<tree default_order="name">

- And can inherit base view with following syntax (Descending example)

<xpath expr="//tree" position="attributes">
        <attribute name="default_order">name desc</attribute>
</xpath>

アバター
破棄