Skip to Content
Menu
This question has been flagged
1 Reply
7645 Views

Hi guys,

What is the correct way to order the Kanban from projects?
The first thing I did was to add a default_order in the arch (project_view.xml) but this didn't change anything:

<record model="ir.ui.view" id="view_project_kanban">
            <field name="name">project.project.kanban</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <kanban class="oe_background_grey">
                   <kanban default_order="name" />
                  //irrelevant code

               </kanban>
            </field>

Then I went into project.py and found the method _get_type_common which orders the projects in kanban view. By default its like this:

def _get_type_common(self, cr, uid, context):
        ids = self.pool.get('project.task.type').search(cr, uid, [('case_default','=',1)], context=context)
        return ids
    _order = "sequence, id"
    //irrelevant code

So I thought I'd change the _order="sequence,id" to _order="name" but the field 'name' is not in the model project.project..So I thought I'd change it to this:

_order = "type_ids.name"

But then I get the following error:

AccessError

Invalid "order" specified. A valid "order" specification is a comma-separated list of valid field names (optionally followed by asc/desc for the direction) 

So, what is the correct way to order on the name of the project in the Kanban view then?

 

Update: New code now looks like this:

class project(osv.osv):
    _name = "project.project"
    _description = "Project"
    _inherits = {'account.analytic.account': "analytic_account_id",
                 "mail.alias": "alias_id"}
    _inherit = ['mail.thread', 'ir.needaction_mixin','project.project']
    _order = 'name asc'
    name = fields.char('Account/Contract Name', required=True, track_visibility='onchange')

With kind regards,

Yenthe

Avatar
Discard
Best Answer

Try this:

class project(models.Model):
    _name = "project.project"
    _inherit = ['project.project']
    _order = "name asc"

    name = fields.Char('Account/Contract Name', required=True, track_visibility='onchange')

 UPDATED:

### name = fields.Char('Account/Contract Name', required=True, track_visibility='onchange')

Avatar
Discard
Author

Thanks for the answer zbik! I've tried this but it gives me KeyError: 'project.project'. I've updated my question with the new code.

depends?

PS. you inherit only _inherit = ['project.project']

Author

Zbik I believe your example code is for in a custom module? I would like to simply replace/modify the code in the current project module. In the current module I'd need the 'mail.thread', 'ir.needaction_mixin', too.

You inherit project.project -> project.project inherit mail.thread and ir.needaction_mixin = you inherit all

Author

Sorry for the late reply Zbik! So I've created a new module and installed this. Everything works fine until I try to open up any of the projects. I then get a programmingError saying the column doesn't exist. As you can see here: http://i.imgur.com/YSCwmJh.png why is my Odoo throwing this up? The field does exist..

Author

You can find the module here in case you want to test it / see whats wrong: https://github.com/Yenthe666/order_projects_by_name

In my test system, I have oher error when create new project and when name = fields.Char() is defined (??? hmmm ???). When I comment this line and update module all works ok.

Author

I already removed the name field Zbik, as you can see here: https://github.com/Yenthe666/order_projects_by_name/blob/master/order_projects_by_name/models.py but even then I get errors. It only happens when you open up project tasks by clicking on a project, not when showing the project overview etc.

Strange, I do not have such a issue. Try to remove and re-install the module.

Related Posts Replies Views Activity
0
Mar 22
1572
1
Dec 19
4145
3
Dec 17
5470
0
Sep 17
2797
1
Jul 20
3753