跳至內容
選單
此問題已被標幟
4 回覆
68803 瀏覽次數

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>

頭像
捨棄