Odoo Help

2

3
2 答案
5
头像

Remya 印度

--Remya--

5897
| 8 8 10
Thiruvananthapuram, 印度
--Remya--

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

Remya 印度
2014/7/30 上午3:59

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...

1 备注
Alcaline 菲律宾
2014/7/30 上午4:29

thanks:)

0
头像

Prakash 印度

--Prakash--

11641
| 6 7 9
Bikaner, 印度
--Prakash--

OpenERP Developer at SunARC Technology

Prakash 印度
2014/7/30 上午3:44

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),
    }

 

1 备注
Alcaline 菲律宾
2014/7/30 上午4:29

thanks:)

提问
Writer
Keep Informed
1 关注者(s)
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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now