Odoo Help


Python - Populating many2one field on loading of form OpenERP

Saghir A. Khatri
on 9/12/14, 3:29 AM 1,918 views

I am trying to load my form's many2one field when form load's with a query to populate filtered ids of product. I achieved this in my Onchange method, but i am not sure how i can do it on loading of form in many2one field.

All I want here is to return the results of the query to my product_id field which is a many2one field.?

On 9/12/14, 8:41 AM

Hi, you can achieve this functionality by writing the default_get orm method of openerp, this method will be called whenever a new form is opened to create.

may i use cr.exucte(query) in this method??

Saghir A. Khatri
on 9/12/14, 9:00 AM

i tried this ` def default_get(self,cr,uid,ids,context=None): print 'new function'` but it removed all fields on my form... I can see labels only

Saghir A. Khatri
on 9/12/14, 9:02 AM

Saghir, it is always adviseable if you inherit ORM standard method (default_get is one of them) to return what the super is returning. So, you can add super(class_name, self).default_get(cr, uid, ids, context=context) as your last line in the default_get method that you have overriden. Yes, you can execute query in that method, but why are you not using ORM method (search) instead?

on 9/13/14, 2:20 PM

default_get() is an ORM function. If you re-define it, you need to add a super() call. So, res = super(some_class, self).default_get(cr, uid, ids, context=context). Then parse out res and append your changes. The arguments in default_get() aren't quite right either. Check the technical memento, page 4, for more explanation on ORM functions: https://www.odoo.com/files/memento/OpenERP_Technical_Memento_latest.pdf Or better yet, just look at orm.py, those main functions have more info commented into them.

Brett Lehrer
on 9/13/14, 2:34 PM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 9/12/14, 3:29 AM
Seen: 1918 times
Last updated: 3/16/15, 8:10 AM