Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Set default value in object of many2one field

Avatar
odoo
Avatar
Discard
1 Answer
0
Avatar
odoo
Best Answer

Define default Method Code

def _get_default_category(self, cr, uid, context=None):
        res = self.pool.get('model.category').search(cr, uid, [('name','=',categroy_name)], context=context)
        return return res and res[0] or False
_defaults = {
     'category_id':_get_default_category,
}
4 Comments
Avatar
Discard
Avatar
odoo
-

This is not what I want exactly, Your method will give category_id by default based on function. But I want to set type of model.category based on active object(e.g. test.test).

Avatar
odoo
-

so you can try on_change function based on the change object(test.test) field value model.category value set in the on change method

Avatar
odoo
-

on change method will be called while I enter some value in some field. If I directly create record, and then create category from test.test default type should come. Is it possible to do ? For example: Create product, then create Contract from product form, by default employee should come as Administrator.

Avatar
odoo
-

Thanks Prakash, great example!