Odoo Help


How to define a default country value for the partner form in my custom module?

Francisco Luz
on 4/13/14, 1:35 AM 2,060 views

FYI I am aware that one could define default values for any field through the developer mode User Interface.

I would like though to define my default values on my custom module. For the partner object specifically, I presume the way to go is something like:

from openerp.osv import orm, fields

class MyModule(orm.Model):
    _inherit = 'res.partner'
   _defaults = {
       # Not quite sure how to set the default value for country here.

Med Said BARA

--Med Said BARA--

| 5 5 7
--Med Said BARA--
Med Said BARA
On 4/13/14, 7:14 AM

Try using this code - where XX = your country code:

def _default_country(self, cr, uid, context=None):

    cid = self.pool.get('res.country').search(cr, uid, [('code', '=', 'XX')], context=context)
    if cid: return cid[0]

_defaults = {
    'country_id': _default_country,



| 5 4 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 4/13/14, 7:17 AM

Your solution works also but I had to slightly change the code " _defaults = { 'country': " with " _defaults = { 'country_id': "

Francisco Luz
on 4/13/14, 6:58 PM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 4/13/14, 1:35 AM
Seen: 2060 times
Last updated: 3/16/15, 8:10 AM