Odoo Help


how to add deafult value to a field?

aneesh ATEES Infomedia Pvt Ltd
on 2/17/15, 12:26 AM 3,459 views

how we can add a default value to a feild?pls give me an exmaple


Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 2/17/15, 1:02 AM

Hi Aneesh,

If you are working with odoo 8, using the new api, you can try like this:


from openerp import models, fields, api

class Session(models.Model):
    _name = 'model.name'
    discount = fields.Float(string='Discount (%)',  default = 0.0)
    state = fields.Selection(


You can see, I have set the default values for two fields, discount and state. In new api, you don't need to use '_defaults' to set the default values, you can give it in the field definition itself.

Hope this helps you.


Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--

| 6 5 6
Baroda, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 2/17/15, 12:48 AM

Hello aneesh,

try this code may be helpfull.

write this code in .py file

_columns = {

     'gender' : fields.selection([('m','Male'),('f','Female')],'Gender')


_defaults = {

 'gender' : 'm'


using this code by default value set Male in gender selection field.

if you find this answer helpful, please give me a thumbs up vote    

Thanks & Regards,

Ankit H Gandhi




| 5 3 8
Pondicherry, India
On 2/17/15, 1:24 AM

if you want some small number of fields as default value means ,you can use

_default = {

 'your_field' : 'your_default_value'


otherwise,if you want to diplay more values as default means ,you can use

default_get() method

On 3/3/15, 2:02 AM

If you want to change the default value to something that is not listed in the Default dropdown, then you should do the following (it's way faster and there's no need to change the code):

Fill the field with wanted value which you want to set to default and THEN go to the developer mode, Click on Debug View dropdown (in the upper corner) and select Set Defaults. Now you see you have a NEW (exactly the one you wanted) default value in the dropdown, which you can select.

It can't get any easier than that :)

Hamid Darabi
On 3/2/15, 5:04 PM

Try it my way if you want to make this happen without coding. Just remember that you're setting default values only for your current database. I set the default country name to Canada for new clients in this scenario:

  1. Activate the developer mode in "About Odoo" page
  2. Open a client with your desired values, in this case a client from Canada (You need to see the client in Form View)
  3. On the top left corner choose the "set defaults" in the dropdownlist
  4. In the pop-up window choose "Country = Canada"
  5. Select the target users (only you or everyone)
  6. Click on "Save Default" button

You can do this for different fields in the same form by repeating steps 3 to 6

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

1 follower(s)


Asked: 2/17/15, 12:26 AM
Seen: 3459 times
Last updated: 3/16/15, 8:10 AM