This question has been flagged
4 Replies
12622 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 ?

Avatar
Discard
Best Answer

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!

Avatar
Discard
Author

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.

Hello Amit,

You have any idea how to get active model name for 'One2Many' field ??

For Example when i am apply above condition you are suggest like in tree view i am apply active_model then i will get 'sale.order' but how to get 'sale.order.line'.

Best Answer

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    


Avatar
Discard
Best Answer

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.

Avatar
Discard