Use the "id" field in a view

Asked by Francois Degrave

Hi!

I would like to use the "id" field for domain purposes in a view. In __view_look_dom_arch of orm.py file I read this (l. 1666):

 # sometime, the view may contain the (invisible) field 'id' needed for a domain (when 2 objects have cross references)

Unfortunately, if I use this id field in a view, it crashes because "id" does not appear in _columns ("key error").

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Francois Degrave
Solved:
Last query:
Last reply:
Revision history for this message
Naresh(OpenERP) (nch-openerp) said :
#1

Hello Francois,

may be you need to see this first:https://bugs.launchpad.net/openobject-server/+bug/815903

Hope this helps !

Thanks

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) said :
#2

Hi Francois,

what worked for me is to explicitely declare the field in the model columns. It does not affect the database structure, but it makes the field available for purposes such as yours.

The same thing happens at a number of occasions in the official addons. Here is an example from the crm_claim module:

    'id': fields.integer('ID', readonly=True),

Cheers,
Stefan.

Revision history for this message
Francois Degrave (fde-be) said :
#3

Thanks Stefan!

On my side what I did is monkey patching the "read" method to get rid of "id" in the fields argument, in order to avoid this key error. But thanks for the tip anyway!