This question has been flagged
2 Replies
11719 Views

lets say we have a module A which has a one2many field to module B and a company field. after choosing company in the form view from module A we click on "Add an Item" to add an item to the one2many field, which opens the view form from module B.

how can I e.g. automatically set the company in module B to the same which was selected in view from module A?

thank you.

Avatar
Discard
Best Answer

context

You probably want something like context="{'company_id':company_id}" and this would go on the field that represents the one2many relationship

See also https://accounts.openerp.com/forum/Help-1/question/8598

Avatar
Discard
Author

_defaults = { 'a_field' : lambda self, cr, uid, context : context['a_field'] if context and 'a_field' in context else None }

Author Best Answer

thanks, another thing we need is the following:

_defaults = { 'a_field' : lambda self, cr, uid, context : context['a_field'] if context and 'a_field' in context else None }

Avatar
Discard