Odoo Help

Welcome!

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

4

How to set default language in res_partner.py

By
Pravitha
on 5/24/13, 6:36 AM 2,584 views

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?

6

Omal Bastin

--Omal Bastin--
1146
| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 5/24/13, 8:53 AM

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

This was what i wanted

Pravitha
on 6/18/13, 5:22 AM
9

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 5/24/13, 8:39 AM

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

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

Pravitha
on 5/24/13, 8:52 AM

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']

Omal Bastin
on 5/24/13, 8:57 AM

is this a selection field ??

Sandeep
on 5/24/13, 9:06 AM

this will work for money2one relation

Sandeep
on 5/24/13, 9:07 AM

yes it is a selection field

Pravitha
on 5/24/13, 9:11 AM

see updated answer now

Sandeep
on 5/24/13, 9:14 AM

all the available language will be seen into that selection field

Sandeep
on 5/24/13, 9:15 AM

its actually wrong!! please check it

Omal Bastin
on 5/24/13, 9:18 AM

whats wrong?? , let me know

Sandeep
on 5/24/13, 9:22 AM

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

Sandeep
on 5/24/13, 9:30 AM

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

Omal Bastin
on 5/24/13, 10:02 AM

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

Sandeep
on 5/24/13, 10:03 AM

:-) nothing more to say

Omal Bastin
on 5/24/13, 10:08 AM

thankyou for the help sir

Pravitha
on 6/18/13, 5:21 AM

ok that's fine

Sandeep
on 6/18/13, 5:30 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/24/13, 6:36 AM
Seen: 2584 times
Last updated: 2/29/16, 11:17 AM