Help

5

How to apply context on one2many filed.?

Hello Everyone,

I have to try to implement to get default value in my one2many filed. In side one2many field "client_name" get default from sale order  "partner_id". so how to do this. 

I am try to set context :

<field name = "client_name" context = "{'default_customer':parent.partner_id}"/>

And call on my field

@api.multi
def _get_customer_name(self):
ctx = self.env.context
print "context::",ctx
client_name = filed.Many2one('res.partner' , default= _get_client_name)

and my output is :

context::: {'lang': u'en_US', 'tz': u'Asia/Kolkata', 'uid': 1}

and when i am try to apply context on my one2many field it's show Error:

Error: KeyError: 'partner_id'

So any suggestion. 

Thanks for Help In Advanced.

Avatar
Discard
1 Answer
2
Avatar
Sushma
Best Answer

Hi Manish,

1. can be done using related field, like:

client_name = fields.Many2one(related='order_id.partner_id', store=True, string='client name')

2.using context :

<field name = "client_name" context = "{'client_name':parent.partner_id}"/>

2 Comments
Avatar
Discard

Thanks it's working.

Avatar
Sushma
-

Great!