コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
9046 ビュー

Must be some basic stuff, but I would like to know how I can sort projects by End Date. I have tried below in an addon module...

from openerp.osv import fields, osv
class project(osv.osv):
    _inherit = 'project.project'
    _name = 'project.project'
    _order = 'date'

And I get this error.

ProgrammingError: column "date" does not exist
LINE 1: ...0, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63) ORDER BY date

I realize that the original project class _inherits "account.analytic.account" which is where the End Date comes from. In such case how can we use a field that belong to the original model in sorting?

アバター
破棄
最善の回答

Hello, I found the solution, here in project object , it inherits account.analytic.account object. and this 'date' field is made in account.analytic.account object. so we must have to use following method, Try this,

class project(osv.Model):
    _inherit = "project.project"
    _order = 'date2'
    _columns = {
        'date2': fields.related('analytic_account_id', 'date', string="End Date", type='date', store=True),
    }

and no need of _name = 'project.project' so,

remove

_name = 'project.project'

Hope it work for you.

アバター
破棄
著作者

I tried your edited content (just remove _name = 'project.project') but I still get the same error as in the original question ("ProgrammingError: column "date" does not exist")...

Hey Ypshi, see my updated answer. the problem was, date field is made in account.analytic.account object. so we can not order date field directly from project.

Hey Yoshi, Is your problem is solved?? if yes then please mark my answer as solved. Thanks.

著作者

I still get the error "ProgrammingError: column project_project.date does not exist". Something must be missing...

You must have to update your module. Go through Settings >> Modules >> Installed Modules. search your module and upgrade it.

著作者

I totally forgot to do that. It solved the problem. Then I got another problem of "End Date" being blank (thus the sorting didn't work), so I changed the field name to "date2" for the code to work. Thanks a lot for your advice!

please mark my answer as solved if your problem is solved. thanks.. :)

関連投稿 返信 ビュー 活動
3
2月 24
12359
0
12月 24
9482
3
9月 24
21708
5
12月 24
52994
4
7月 24
10597