Help

4

How to set default language in res_partner.py

Avatar
Pravitha

I have defined a new language named English-India and its code is en_GB and I want to get this language as default set on language field when a customer and user is created.I overridden res_users.py and res_partner.py and I gave the following code to _defaults of res_users and `res_partner.

_defaults = {
    'lang':'en_GB',
    }

In user creation the language field is English-India by default but its not working in customer creation. Can some one help?

Avatar
Discard
2 Answers
7
Avatar
Omal Bastin
Best Answer

Hi, Goto Settings > Technical > Actions > User defined Defaults, there you can find that default value is set as en_US, you can delete this record or change it to your language

1 Comment
Avatar
Discard
Avatar
Pravitha
-

This was what i wanted

9

Hey Pravitha

DO it as below :

inherit your res.partner

and add this new function in that class (res_partner)

   def _get_mylang(self, cr, uid, context=None):
         ids = self.pool.get('res.lang').search(cr, uid, [], context=context)
         res = self.pool.get('res.lang').read(cr, uid, ids, ['code', 'name'], context)     
         return [(j['code'], j['name']) for j in res] + [('','')]

and then just add this method in _defauts link below

   _defaults = {
       'lang':_get_mylang,
}

or also you can go through -- > Settings > Technical > Actions > User defined Defaults thats it

Thanks
Sandeep

15 Comments
Avatar
Discard
Avatar
Pravitha
-

Helo sir, Thankyou for the reply . can i ask you somthing will it show english also in the selection?

Avatar
Omal Bastin
-

Hi, your function will only return the id of the language. then lang field is actually a selection. So the function should be like def _lang_get(self, cr, uid, context=None): lang_pool = self.pool.get('res.lang') ids = lang_pool.search(cr, uid, [('code','=','en_GB')], context=context) res = lang_pool.read(cr, uid, ids, ['code'], context) return r['code']

is this a selection field ??

this will work for money2one relation

Avatar
Pravitha
-

yes it is a selection field

see updated answer now

all the available language will be seen into that selection field

Avatar
Omal Bastin
-

its actually wrong!! please check it

whats wrong?? , let me know

man, it should not be wrong .......:))

Avatar
Omal Bastin
-

your _get_mylang will return a list of tuples. To get a default value, you need to pass the key value of the selection list. jou just check it in your local server

oh man it is fine .:):) and for your information ,, selection gets tuple value with (key,value)

Avatar
Omal Bastin
-

:-) nothing more to say

Avatar
Pravitha
-

thankyou for the help sir

ok that's fine