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.

0

Set default value in object of many2one field

By
Jagdish Panchal
on 12/18/13, 6:52 AM 6,798 views

Hello all,

I have created many2one field for category in my object. Based on my object value, I want to set default value for 'type' field of Category.

Can anybody help me how to do it?

Thanks

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 12/18/13, 7:14 AM

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

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

Jagdish Panchal
on 12/18/13, 7:32 AM

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

Prakash
on 12/18/13, 7:36 AM

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.

Jagdish Panchal
on 12/18/13, 7:40 AM

Thanks Prakash, great example!

Yenthe
on 4/10/15, 2:27 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

0 follower(s)

Stats

Asked: 12/18/13, 6:52 AM
Seen: 6798 times
Last updated: 3/16/15, 8:10 AM