تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
5982 أدوات العرض

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?

الصورة الرمزية
إهمال
أفضل إجابة

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

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

أفضل إجابة

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...

الكاتب

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 !

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 15
3599
1
أبريل 23
4664
3
سبتمبر 22
6153
1
يونيو 22
2685
2
أبريل 22
6193