Search code examples
pythonodooopenerp-7

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)]),

Solution

  • 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)]"
    />