[Trunk,6.1 ] Order by don't work for related fields

Asked by wowas

Order by don't work for related fields.

For examples:
1)
class mega_maintenance_order(osv.osv):
    _name = 'mega.maintenance.order'

    _columns = {
        'name': fields.char('Name', size=64, required=True),
        'counter_id': fields.many2one('mega.maintenance.counter', 'Planned Counter', ondelete='cascade'),
        'date_order': fields.related('counter_id', 'date', type='date', string='Planned Date'),
    }

    _order = 'date_order desc'

Will generate an error.

ProgrammingError: column "date_order" does not exist
LINE 1: ..._order".id FROM "mega_maintenance_order" ORDER BY date_order...
                                                                                                                          ^

2)
order_ids = self.pool.get('mega.maintenance.order').search(cr, uid, [], limit=1, order='date_order desc')

Will not sort order by 'date_order'

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Vivek poddar
Solved:
Last query:
Last reply:
Revision history for this message
Amit Parik (amit-parik) said :
#1

Helllo Wowas,

Its already worked under offical code, please check the product.product object on product module's 'name_template' field.

Would you please check the line number 536 and 555 of product/product.py and remove the 'default_code' under _order then try. You will see all are working correct.

You might have a mistake on your code. You was given the 'counter_id' as m2o and your related field's type is date. So you have change the type of the date_order is type='manyo2one' or change the counter_id 's type=''date.

Your this mistake is created this error.

Hope this will help you!

Note: date is again data type on postgres so better not to give date name for field , So I would like to suggest don't give field name "date".

Thanks for the reporting!

Revision history for this message
Ferdinand (office-chricar) said :
#2

we have made a server patch for 6.0. which sorts related and functional fields

Revision history for this message
Best Vivek poddar (vivekimsit) said :
#3

Hi!

I think storing the related field in the db might solve the issue.

Thanks and Regards!
Vivek Poddar

Revision history for this message
wowas (wowas18) said :
#4

Thanks Vivek poddar, that solved my question.

Revision history for this message
wowas (wowas18) said :
#5

Attribute store=True solve problem.

Without it product.product object have the same error.