forvas
forvas

Reputation: 10189

How to get current ID record in a domain field in OpenERP7?

Simple OpenERP7 question:

I adding a new field to a model. This field is a many2one. It is going to show every active partner which has a specific parent_id: this parent_id must be the ID of the current record. How can I do this?

Here, one of my failed attempts. It should be something like this:

'main_contact_id': fields.many2one('res.partner', 'Main Contact', domain=[('active','=',True), ('parent_id','=',self.id)]),

Upvotes: 1

Views: 3111

Answers (2)

forvas
forvas

Reputation: 10189

Done!!

This is the way to manage this:

<field
      name="main_contact_id"
      domain="[('parent_id','=',context.get('active_id', False))]"
/>

or

<field
      name="main_contact_id"
      domain="[('parent_id','=',active_id)]"
/>

Upvotes: 1

Adrian Merrall
Adrian Merrall

Reputation: 2499

You can't do this in the model definition as there is no concept of the ID of the current record (this is the model definition after all, not an instance of a record). You should add this domain on the field in the form and you should be able to use ID from memory. Domains in a model can only use static information such as your active = True.

Upvotes: 1

Related Questions