Could not set "_order=name" for object which inherits from product

Bug #858006 reported by tnbui
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Wishlist
OpenERP's Framework R&D

Bug Description

This bug is another improvement of comment 10 from bug: https://bugs.launchpad.net/openobject-server/+bug/823691

Steps to reproduce:
+ In object "hotel.room" of module "hotel", set "_order = 'name'" to order Room list by name
+ View list of Rooms, then below error occurred

Traceback (most recent call last):
  File "/home/tubui/source_code/trunk6-new/server/bin/netsvc.py", line 489, in dispatch
    result = ExportService.getService(service_name).dispatch(method, auth, params)
  File "/home/tubui/source_code/trunk6-new/server/bin/service/web_services.py", line 599, in dispatch
    res = fn(db, uid, *params)
  File "/home/tubui/source_code/trunk6-new/server/bin/osv/osv.py", line 122, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/tubui/source_code/trunk6-new/server/bin/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/tubui/source_code/trunk6-new/server/bin/osv/osv.py", line 167, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/tubui/source_code/trunk6-new/server/bin/osv/orm.py", line 1743, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/home/tubui/source_code/trunk6-new/server/bin/osv/orm.py", line 4045, in _search
    cr.execute('SELECT "%s".id FROM ' % self._table + from_clause + where_str + order_by + limit_str + offset_str, where_clause_params)
  File "/home/tubui/source_code/trunk6-new/server/bin/sql_db.py", line 78, in wrapper
    return f(self, *args, **kwargs)
  File "/home/tubui/source_code/trunk6-new/server/bin/sql_db.py", line 131, in execute
    res = self._obj.execute(query, params)
ProgrammingError: column "name" does not exist
LINE 1: SELECT "hotel_room".id FROM "hotel_room" ORDER BY name limi...

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello,

Currently, _order supports any complex syntax that PostgreSQL supports. It can be completely arbitrary, including multiple columns, database functions, etc. As a result, we can't easily extract column names from it, and find out if we need to JOIN the parent table for _order on inherited fields to work. And always adding the JOIN(s) might introduce performance penalties but could also lead to issues in case of ambiguity between column names in the parent and child tables.
So what you describe in the bug report is simply not meant to be possible at the moment, it's a technical limitation.

If you look at the product.product class, you will see that _order refers to local product.product columns, including a stored related field containing the name of the template. This is a possible workaround for your use case: add any necessary related+stored field you need, in order to be able to define the _order based exclusively on 'local' columns.

We will keep this bug report as wishlist, as there are a few options we can investigate in order to enable this in the future, but this is not in the scope of the framework for now.

By the way, having multiple levels of _inherits is not often a good design choice (but that's a different topic)

Thanks for suggesting this improvement!

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
tnbui (tnbui-it) wrote :

Thks for your answer. In the mean time, I'll use "related+stored" field to order the object.

Have a nice day,
Tu

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.