Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
13386 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

Thanks it's working.

Great!

Powiązane posty Odpowiedzi Widoki Czynność
3
gru 17
3901
5
sty 20
4012
2
paź 22
8453
1
gru 23
32979
0
kwi 17
6534