Eric Lee
Eric Lee

Reputation: 710

Odoo 9 How to sort order for a field in form view

I've been trying to modify project issue object.

and When I click Assign to field, It shows a list of users with dropdown.

But I'd like to change its order to DESC.

Is there any thing I can do in View?

here is my code below

<record id="project_issue_custom_form" model="ir.ui.view">
    <field name="inherit_id" ref="project_issue.project_issue_form_view"/>
    <field name="model">project.issue</field>
    <field name="arch" type="xml">
        <field name="user_id" position="attributes">
            <attribute name="default_order">sequence desc</attribute>
        </field>
    </field>
</record>

Also I tried in controller

class Project_issue(models.Model):
    _inherit = "project.issue"
    _order = "user_id desc"

But It still doesn't affected.

Upvotes: 4

Views: 3532

Answers (1)

CZoellner
CZoellner

Reputation: 14768

The tag default_order can only be used for lists and kanban views. But you want to change the order of the content of a many2one field (user_id on project.issue).

Your second approach has potential. But it is the wrong model:

class ResUsers(models.Model):
    _inherit = "res.users"
    _order = "name desc"  # or id

Upvotes: 2

Related Questions