Odoo Help


How do i get active_id in my one2many field ?

Kalmen Chia / E-Global SCM Solutions Sdn Bhd
on 6/7/13, 12:26 AM 5,419 views

Hi ,

i have a class that look something like this.

class myclass(osv.Model):

    def _get_cur_subline_ids(self, cr, uid, ids, field_name, arg, context): {
       //i need my current active class_line id here !!!
       print context
       //expecting to get model_line_id in the context but cannot

    def _srch_subline(self, cr, uid, obj, name, args, context):: {
       //i need my current active class_line id here !!!
       print context
       //expecting to get model_line_id in the context but cannot

    _columns = {
                "name" : fields.char('Desc.',help="enter your description"),
                "class_line_ids" : fields.one2many('class.line', 'class_id', 'Lines'),
                "lines_subline_ids" : fields.function(_get_cur_subline_ids,
                                         string='Products List'

XML for myclass

<field name="class_line_ids" nolabel="1"  context="{'model_line_id': active_id}">

My questions is , how can i get the ACTIVE id of my class_line_ids i.e. when user click on the tree view of the class_line_ids in my form and pass it to the context and then in turn to be used by either the _get_cur_subline_ids or _srch_subline function to filter the return ids of the object "product.product" dynamically ?

Amit Parik (amp)
On 6/7/13, 4:37 AM


You can pass the active_id on context for tree view where you have set the widget="one2many_list" on the attribute you can pass the active_id on context.

As well on any method, If you want to use the active_id, You have to use get the active id from the context by using context.get('active_id').

Thank you!

Not sure whether is bugs , after apply this https://code.launchpad.net/~openerp-dev/openerp-web/7.0-opw-584668-cpa patch , follow where i add context="{'model_line_id': active_id}" at my class_line_ids field , but cannot get the context at the function in my py.

Kalmen Chia / E-Global SCM Solutions Sdn Bhd
on 6/7/13, 7:25 AM



| 4 4 6
Hyderabad, India

On 4/20/16, 3:24 AM


Actualy what you are trying to do is not correct, you can't get the active_id(which according to your requirement is line id from one2many  'class_line_ids') in main object..

as active_id for current object(myclass.class1) fields will be current record id only.. so anywhere writing active_id means you are pointing to myclass.class1 object..

One thing you can do is in xml on field 'class_subline_ids' pass 'class_line_ids' in context...

<field name="lines_subline_ids" nolabel="1"  context="{'model_lines': lines_subline_ids}">

and then use this lines in context at your '_get_current_subline_ids' and '_srch_subline'

Hope it helps    

On 4/19/16, 5:26 PM


Did you find any solution ?

I have the same issus.

Please let me know if there is any way to retrieve active_id on one2many fields.


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/7/13, 12:26 AM
Seen: 5419 times
Last updated: 10/9/17, 6:51 PM