Odoo Help


[8.0] [old api] How to access "active_id" or parent record from one2many embedded form view ?

HIGHCO - Nicolas Clavier
on 6/26/15, 4:40 AM 1,344 views


I am trying to dynamically fill a selection fields with a class method. The field is in the form of a one2many record.

The code is in old_api style. To pass the id of the "parent record" I use the trick of id field passed through context.

I can therefore fill my fields.selection according the the parent.

Problem :during the load of the parent form view, the method _get_select is executed once with invalid context (no sign of my 'partner_id'), which make sense, it building the readonly form view.
Then I click on edit on the parent form, to add a one2many record :  

When the one2many tree view has editable="bottom":
    the method _get_select is executed once more (up to several times more actually !?) 
with valid context : {'partner_id':###}
    BUT the selection field stays 
empty !

When using a dedicated form view one  my one2many, (context="{'partner_id':id, 'form_view_ref' : 'module.custom_view'}")

    then only the selection gets filled in .. (only the write() operation crashes down the road, but that maybe another issue)

Question : 

     How can I safely access the parent_record (or active_id from the context of an embedded one2many field in form view or inline form view (editabe : top/bottom)

Code :

    <field name="abcd"/>
    <field name="id" invisible="1"/>
    <field name="o2m_ids" context="{'partner_id':id}">
    <tree>     <field name="select"/>      </tree>         <form>
            <field name="select"/>

def _get_select(self, cr, uid, context=None): 
"build a list of tuples to fill the select"
        res = []
       if 'partner_id' in context and context['partner_id']:         
        return res

_columns : {      
    'select_field': fields.selection(_get_select, 'Selection Field'),

Refs :

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/26/15, 4:40 AM
Seen: 1344 times
Last updated: 6/26/15, 4:40 AM