Odoo Help


OpenERP load one2many records list

on 3/25/13, 3:13 AM 8,823 views

i have selection field (many2one division field) if i select one division need to load its' employees on the 'notebook section'. how to implement this in openerp 7

Dear Martin, Please check my code @ github from below link.in there 'line 248', when i select division ID need to load workers, whose tagged to relevant division in below notebook section (line 261)

github link


I don't know about anyone, but I'd need a lot more details before I could understand your question.

on 3/25/13, 7:16 PM

@Martin, Post changed. please check & advice me

on 3/25/13, 10:23 PM

priyankahdp could you please post code of this? Github address gives 404 not found.

on 4/25/13, 6:33 AM

Dear Antanas, Link updated :-)

on 4/26/13, 12:51 AM

Thank you.

on 4/26/13, 3:28 AM

Omal Bastin

--Omal Bastin--
Omal Bastin
| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 3/26/13, 4:40 AM

Use a onchange function for your many2one field which will load the data to the one2many field.

def onchange_many2one_field(cr, uid, ids, many2one_field, context=None):
    if many2one_field:
        #find the list of ids that need to be showed in the many2many field and use
        #value.update({'your_many2many_field': ids_you_found}) 
    return {'value':value}


You can use the following example to create your onchange function. This is an onchange function I have created for invoice(just an example)

def onchange_partner_id(self, cr, uid, ids, type, partner_id,\
        date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
    res = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id, 
            date_invoice=date_invoice, payment_term=payment_term, partner_bank_id=partner_bank_id,

    invoice_lines = []
    product_ids = self.pool.get('product.product').search(cr, uid, [],limit=5)
    for p in self.pool.get('product.product').browse(cr, uid, product_ids):
                          }))#this dict contain keys which are fields of one2many field 
    return res

if there is only single line to be added then res['value'].update({ 'one2many_fieldmname':[(0,0,{'field1':value1,'field2':value2,'fieldn':valuen})] })

In the above example I am searching 5 products and these products are added in the invoiceline. So in your onchange function also you have to search the employee which comes under the division.

In your code,in the form "bpl_work_offer_form" you have add the onchange function at the field bpl_division_id.(in my example partner_id is the many2one field and invoice_line is the one2many field.)

You need to more careful when using onchange to load the one2many field. In the onchange function you have to first unlink all the records loaded in your many2one field. because if once the record is saved then if the onchange is again loaded then a new line will be created. so you need to manage it correctly.

Reference : http://doc.openerp.com/trunk/developers/server/06_misc_on_change_tips/

thanks Omal, how is my function will be.?

on 3/26/13, 4:45 AM

answer update. please check it

Omal Bastin
on 3/26/13, 6:08 AM

thanks Omal :-)

on 3/26/13, 12:18 PM

this is not working for me it says AttributeError: 'super' object has no attribute 'onchange_planned_qty_id'

Lady Sharmane Udtuhan
on 10/21/13, 3:23 AM

post what you have done..its error log and all

Omal Bastin
on 4/16/14, 4:32 AM
wilson zauma
On 3/20/14, 6:05 PM

define in my class:

class stock_picking(osv.osv):
    _name = 'stock.picking' 
    _inherit = 'stock.picking'
    _columns = {
     'aux_almacen_orig': fields.selection(_buscar_shortname_alm,method="True", type="char", size=256, string="Almacen Origen" ),

then i define the function this way:

def _buscar_shortname_alm(self, cr, uid, context=None):
 obj = self.pool.get('stock.location')
        ids = obj.search(cr, uid, [])
        res = obj.read(cr, uid, ids, ['shortcut', 'id'], context)
        res = [(r['id'], r['shortcut']) for r in res if r['shortcut'] != False]
        return res

note: i define shorcut in my class stock location, this field only for to short the complete name in mi case, but you can change with another field that you have in your class:

class stock_location(osv.osv):
    _name = "stock.location"
    _inherit = "stock.location"
_columns = {
        'shortcut' :  fields.char('Nombre Corto',size=50),

and finally this is the result http://(w)(w)(w). orchidshouseperu.com/screenshots/Captura%20de%20pantalla%20de%202014-03-20%2015:52:20.png

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

2 follower(s)


Asked: 3/25/13, 3:13 AM
Seen: 8823 times
Last updated: 7/5/15, 8:00 AM