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.

2

what is CONTEXT?

By
Alcaline
on 7/30/14, 2:25 AM 1,542 views

Does anybody here knows what is the context and what is the use of this??

 

<field colspan="4" name="commit_line_ids" nolabel="1" widget="one2many_list" mode="tree" context="{}" readonly="False">

5

Remya

--Remya--
5813
| 7 8 8
Thiruvananthapuram, India
--Remya--

Working as an Senior ODOO developer. http://in.linkedin.com/pub/remya-r/69/a23/298

Remya
On 7/30/14, 3:59 AM

Context is used to pass arbitrary contextual information to the server.

For example, on a one2many field on the partner object, you may put context="{'partner_id' : active_id}". This information is then available to the server when generating the forms that pop up from the one2many field, for example in '_defaults' field functions. However the object is not (necessarily) filtered by anything you put into the context, only if the object designer has decided that it should be.

One neat little trick actually is to use the context to pass in default values for fields. E.g. to pass in a default value for a 'name' field, use: context="('default_name' : 'David')"

Another use for Context is on buttons. You can use it to pass parameters to object functions. E.g.:

View XML:

Code:

<button string="Click Me" type="object" name="my_func" context="{'param' : 'param_val'}" />


Object Code:

Code:

def my_func(self, cr, uid, ids, context={}):
    # do stuff using the info passed in the context variable...

thanks:)

Alcaline
on 7/30/14, 4:29 AM
0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 7/30/14, 3:44 AM

You can set the context parent value in onemany field in xml file and get the context value in python in default method or on_change method.

For example,

_name = "sample.order"

_columns = {

'partner_id': fields.many2one('res.partner', 'Customer'),

'order_line': fields.one2many('sample.order.line', 'order_id', 'Order Lines', readonly=True),

}

<field name="order_line"  context="{'partner_id':parent.partner_id}" nolabel="1" colspan="4">

_name = "sample.order.line"

  _columns = {

'order_partner_id': fields.many2one('res.partner', 'Customer'),

}

_defaults = {
        'order_partner_id' : context.get('partner_id', False),
    }

 

thanks:)

Alcaline
on 7/30/14, 4:29 AM

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: 7/30/14, 2:25 AM
Seen: 1542 times
Last updated: 8/5/15, 1:35 PM