Odoo Help


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.


[SOLVED]: Default country name ... how to?

Dr Obx
on 3/17/16, 12:41 PM 834 views

Hello everyone.

Recently, I found that I would like to have country name set as default so user will not have to pick it from list (because most of our customers are local - UK).

So to do it I modified class in res_country.py ...

class Country(osv.osv):

_name = 'res.country'

_description = 'Country'

def _get_country_name(self):

res = self.env['res.country'].search([('name','=','United Kingdom')])

print res

return res

_columns = {

'name': fields.char('Country Name',

help='The full name of the country.', required=True, translate=True),

'code': fields.char('Country Code', size=2,

help='The ISO country code in two chars.\n'

'You can use this field for quick search.'),

'address_format': fields.text('Address Format', help="""You can state here the usual format to use for the \

addresses belonging to this country.\n\nYou can use the python-style string patern with all the field of the address \

(for example, use '%(street)s' to display the field 'street') plus

\n%(state_name)s: the name of the state

\n%(state_code)s: the code of the state

\n%(country_name)s: the name of the country

\n%(country_code)s: the code of the country"""),

'currency_id': fields.many2one('res.currency', 'Currency'),

'image': fields.binary("Image"),

'country_group_ids': fields.many2many('res.country.group', 'res_country_res_country_group_rel', 'res_country_id', 'res_country_group_id', string='Country Groups'),


_sql_constraints = [

('name_uniq', 'unique (name)',

'The name of the country must be unique !'),

('code_uniq', 'unique (code)',

'The code of the country must be unique !')


_defaults = {

'address_format': "%(street)s\n%(street2)s\n%(city)s %(state_code)s %(zip)s\n%(country_name)s",

'name': _get_country_name,


I was hoping that it is so easy to achieve but unfortunately .... is not.

How can I achieve it ?

Would anyone tell me what is the best method ?

Don't know why I tried to achieve it in such complicated way .... ;)

The easiest way is via the UI:


(For v7 but it hasn't changed).

Since this is just a record, you can export it like any other to move it from one database to another. 

Bista Solutions US, Ray Carnes
on 3/17/16, 2:05 PM
Dr Obx
On 3/18/16, 5:33 AM

Awesome, it's so simple

in class res_partner(osv.Model, format_address):

just added in _defaults section:

  'country_id': 233,

works beautifully ;)


Ray Carnes

--Ray Carnes--
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 3/18/16, 1:39 PM

I'm glad you got it working.

Just in case you or anyone reading this wants to do it via the UI, the trick is to populate the field BEFORE opening the Set Defaults popup:

This method makes a record in Settings --> Technical --> Actions --> User Defined Defaults:

By removing the User, it becomes the default for ALL USERS (or you can just select that on the popup in the first place).

Awesome, Thank you Ray. Are you sure this or similar method also works in v8.0 ?

Dr Obx
on 3/20/16, 5:39 PM
Yes.  6.1, 7, 8 and 9.

From: Dr Obx
Sent: ‎3/‎20/‎2016 2:39 PM
To: Ray Carnes
Subject: Re: Re: [SOLVED]: Default country name ... how to?

Awesome, Thank you Ray. Are you sure this or similar method also works in v8.0 ?


Robert A.Lien
Sent by Odoo S.A. using Odoo
Bista Solutions US, Ray Carnes
on 3/20/16, 10:10 PM

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

1 follower(s)


Asked: 3/17/16, 12:41 PM
Seen: 834 times
Last updated: 3/18/16, 1:39 PM