How to order by inherited function field?

Asked by Martin Collins

More inheritance troubles...

I have a model which inherits res.partner.category but with a different _name. I want to _order it by the field 'complete_name' which is in the parent object, and it is a non-stored function field. I get this error:

  db.cursor:Programming error: column "complete_name" does not exist

If I _order by 'name', which is also in the parent, it works.

Interestingly, if I copy the 'complete_name' field and its two functions into my model I still get the same error.
I've tried to _order by a function field on a non-inherited model and it works.

Is there any way to get this working?

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Collins
Solved:
Last query:
Last reply:
Revision history for this message
Numérigraphe (numerigraphe) said :
#1

On regular OSV objects, ordering is done by the database so if you want to order on a function fields you have to store it there using the "store={}" attribute in the field definition.
Lionel

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) said :
#2

notice that you can eventually also override the "search" method (usually
it's slower so you do it selectively based on some context value and else
just call super).

2010/11/18 Numérigraphe <email address hidden>

> Question #134571 on OpenObject Server changed:
> https://answers.launchpad.net/openobject-server/+question/134571
>
> Status: Open => Answered
>
> Numérigraphe proposed the following answer:
> On regular OSV objects, ordering is done by the database so if you want to
> order on a function fields you have to store it there using the "store={}"
> attribute in the field definition.
> Lionel
>
> --
> You received this question notification because you are a member of
> OpenERP Committers, which is an answer contact for OpenObject Server.
>

Revision history for this message
Martin Collins (mkc-steadfast) said :
#3

Yes, I should have realised it's done by the database, I saw the query.
Overriding search() and setting context values everywhere seems like a bit of a hack so I've made the field stored and copied in the two functions that build the data. That only left the recursion check function in the parent so I copied that too and dumped the inheritance.

Thanks for the help guys.