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.

1

How do i get active_id in my one2many field ?

By
kalmenchia
on 6/7/13, 12:26 AM 3,497 views

Hi ,

i have a class that look something like this.

class myclass(osv.Model):
    _name="myclass.class1"

    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,
                                         type='one2many',
                                         obj="product.product",
                                         method=True,
                                         string='Products List'
                                         fnct_search=_srch_subline),
                }
myclass()

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 ?

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

Hello,

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.

kalmenchia
on 6/7/13, 7:25 AM
0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 4/20/16, 3:24 AM

kalmenchia,

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    


0
Omar OUHARI
On 4/19/16, 5:26 PM

Hello,

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.

Thanks.

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/7/13, 12:26 AM
Seen: 3497 times
Last updated: 11/23/16, 4:21 AM