How do change the default sort order of different trees for sale.order.line
for example : order by name
<record id="_view_sale_order_line_tree" model="ir.ui.view">
<field name="name">sale.order.line.tree1</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="priority" eval="1"/>
<field name="arch" type="xml">
<tree string="Sales Order Lines" >
<field name="name"/>
<field name="sequence"/>
</tree>
</field>
</record>
order by sequence
<record id="_view_sale_order_line_tree2" model="ir.ui.view">
<field name="name">sale.order.line.tree2</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<tree string="Sales Order Lines" >
<field name="order_id"/>
<field name="sequence"/>
</tree>
</field>
</record>
By default, SQL Server sorts out results using ORDER BY clause in ascending order. Specifying ASC in order by clause is optional.
The system automatically sorts lists that meet one of the sort order criteria.
On version 8, you can use the attribute default_order in XML code.
In your code:
<record id="_view_sale_order_line_tree" model="ir.ui.view">
<field name="name">sale.order.line.tree1</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="priority" eval="1"/>
<field name="arch" type="xml">
<tree string="Sales Order Lines" default_order="name">
<field name="name"/>
<field name="sequence"/>
</tree>
</field>
</record>
<record id="_view_sale_order_line_tree2" model="ir.ui.view">
<field name="name">sale.order.line.tree2</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<tree string="Sales Order Lines" default_order="sequence">
<field name="order_id"/>
<field name="sequence"/>
</tree>
</field>
</record>
Now I'm looking for a way to manage this on previous versions.
Specially for sorting in ascending or descending order we had attribute.
<record id="_view_sale_order_line_tree2" model="ir.ui.view">
<field name="name">sale.order.line.tree2</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<tree string="Sales Order Lines" default_order="sequence desc">
<field name="order_id"/>
<field name="sequence"/>
</tree>
</field>
Here attribute default_order allow to set ordering of record.
default_order="sequence desc"
and
default_order="sequence asc"
This feature available from version 5.0 to till date of odoo 12.0 version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With