Odoo Help

Welcome!

This community 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.

0

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

By
Nicolas Clavier
on 6/26/15, 4:40 AM 679 views

Hi, 

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 :

<form>
    <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"/>
        </form>
</field>

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']:         
            res.append(('a','b'))
           [...]
        return res

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

Refs :

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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