Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
5857 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

Beste antwoord

the comma after 'no-create'  !

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


Avatar
Annuleer
Auteur

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

Auteur

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 !

Gerelateerde posts Antwoorden Weergaven Activiteit
1
mrt. 15
3462
1
apr. 23
4369
3
sep. 22
5838
1
jun. 22
2549
2
apr. 22
5997