Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do change the default sort order of different trees for sale.order.line

Tags:

xml

odoo

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>
like image 300
Malcon Avatar asked Jan 28 '15 22:01

Malcon


People also ask

What is the default order of sorting?

By default, SQL Server sorts out results using ORDER BY clause in ascending order. Specifying ASC in order by clause is optional.

Which one of the following orders is used by default to sort lists?

The system automatically sorts lists that meet one of the sort order criteria.


2 Answers

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.

like image 122
forvas Avatar answered Nov 16 '22 03:11

forvas


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.

like image 24
Tejas Tank Avatar answered Nov 16 '22 02:11

Tejas Tank