Kiran
Kiran

Reputation: 1531

How to set default value for fields in odoo 8?

I created a checkbox and I want to set its default value to false so that it is unchecked by default.I tried in four ways but still the checkbox is checked by default.

raw = fields.Boolean(default=0)
raw = fields.Boolean(default='0')
raw = fields.Boolean(default=False)
raw = fields.Boolean(default='False')

Upvotes: 1

Views: 7740

Answers (3)

Prakash Kumar
Prakash Kumar

Reputation: 2594

By default value of Boolean field is false so you don't need to set it default value.

Now regarding your query :

raw = fields.Boolean(default='0')
raw = fields.Boolean(default='False')

Both these syntax are using string '0' and 'False' which is True by logic

you can use

raw = fields.Boolean(default=0)
raw = fields.Boolean(default=False)

Upvotes: 2

Dachi Darchiashvili
Dachi Darchiashvili

Reputation: 769

This is an option too:

def default_value(self)
    <code here>
    return something
var = fields.Integer(default=default_value)

Upvotes: 0

Default it's None for boolean field not False(you can check into the database without setting up default value of any boolean field, you will see there None not False), so you just need to set like that

raw = fields.Boolean(string='Raw', default=False)

Upvotes: 2

Related Questions