Odooers论坛

欢迎!

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


0

Set default value in object of many2one field

形象
odoo
形象
丢弃
1 答案
0
形象
odoo
最佳答案

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 注释
形象
丢弃
形象
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).

形象
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

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

形象
odoo
-

Thanks Prakash, great example!