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'),
}
<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'),
}