跳至内容
菜单
此问题已终结
1 回复
13602 查看

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.

形象
丢弃
最佳答案

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}"/>

形象
丢弃
编写者

Thanks it's working.

Great!

相关帖文 回复 查看 活动
3
12月 17
4102
5
1月 20
4286
2
10月 22
8670
1
12月 23
33403
0
4月 17
6706