Odoo Help

Welcome!

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.

1

How can I make my field create a DEFAULT value SQL declaration?

By
Luis Masuelli
on 11/19/15, 4:57 PM 495 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?

0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 11/20/15, 3:56 PM

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.

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

Luis Masuelli
on 11/20/15, 5:30 PM

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',

Drees Far
on 11/22/15, 7:04 AM
0
Maurice Agée
On 11/20/15, 11:22 AM

the comma after 'no-create'  !

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


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

Luis Masuelli
on 11/20/15, 3:09 PM

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

Luis Masuelli
on 11/20/15, 3:09 PM

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

Maurice Agée
on 11/23/15, 10:54 AM

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)

Stats

Asked: 11/19/15, 4:57 PM
Seen: 495 times
Last updated: 11/21/15, 6:11 AM