This question has been flagged
4 Replies
4267 Views

I created this model:

    class ir_model(orm.Model):
        _inherit = 'ir.model'
        _columns = {
            'm2x_creation_lock_type': fields.selection([('no-lock', 'Normal'), ('no-edit', 'Hide Create & Edit'), ('no-create', 'Hide both buttons')], required=True, string='ManyToOne / ManyToMany creation lock type', help="Tells whether the 'Create' or 'Create and Edit' selection items should be displayed or not"),
        }
        _defaults = {
            'm2x_creation_lock_type': 'no-create'
        }

But when the column is created, it does not have a `DEFAULT 'no-create'` part.

How can I make my column have a DEFAULT value part without manually executing SQL on the database?

Avatar
Discard
Best Answer

Hello my friend;

Here is the answer to your question;

class ir_model(orm.Model):

_inherit = 'ir.model'

_columns = {

'm2x_creation_lock_type': fields.selection([('no-lock', 'Normal'), ('no-edit', 'Hide Create & Edit'), ('no-create', 'Hide both buttons')], required=True, string='ManyToOne / ManyToMany creation lock type', help="Tells whether the 'Create' or 'Create and Edit' selection items should be displayed or not"),

}

_defaults = {

'm2x_creation_lock_type': 'no-create',

}

And an example from OpenErp:

class hr_job(osv.osv):

_name = "hr.job"

_description = "Job Description"

_inherit = ['mail.thread']

_columns = { 

'state': fields.selection([('open', 'No Recruitment'), ('recruit', 'Recruitement in Progress')], 'Status', readonly=True, required=True,

help="By default 'In position', set it to 'In Recruitment' if recruitment process is going on for this job position."),

}

_defaults = { 

'state': 'open',

}

Follow this link my friend: https://www.odoo.com/fr_FR/forum/help-1/question/how-to-set-default-value-for-openerp-57740

Best Regards.

Avatar
Discard
Author

Please tell me how is it different from what I posted as my try. It does not create a DEFAULT 'mydefaultvalue' part in the column

i have gave you an example that works fine. so add the comma after 'm2x_creation_lock_type': 'no-create' -> 'm2x_creation_lock_type': 'no-create',

Best Answer

the comma after 'no-create'  !

 _defaults = { 
'm2x_creation_lock_type': 'no-create',
}


Avatar
Discard
Author

The comma? I hope you're talking about coding standard and not about code semantics...

Author

The comma? I hope you're talking about coding standard and not about code semantics...

hello Luis, my answer is correct ? For me, it is same as yours !