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.

1

OpenERP load one2many records list

By
priyankahdp
on 3/25/13, 3:13 AM 8,635 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

https://github.com/priyankahdp/openerp.git

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

Martin
on 3/25/13, 7:16 PM

@Martin, Post changed. please check & advice me

priyankahdp
on 3/25/13, 10:23 PM

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

Antanas
on 4/25/13, 6:33 AM

Dear Antanas, Link updated :-)

priyankahdp
on 4/26/13, 12:51 AM

Thank you.

Antanas
on 4/26/13, 3:28 AM
2

Omal Bastin

--Omal Bastin--
1146
| 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):
    value={}
    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}

or

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,
            company_id=company_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):
        invoice_lines.append((0,0,{'product_id':p.id,'name':p.name,
                          'account_id':p.categ_id.property_account_income_categ.id,
                          }))#this dict contain keys which are fields of one2many field 
    res['value']['invoice_line']=invoice_lines
    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.?

priyankahdp
on 3/26/13, 4:45 AM

answer update. please check it

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

thanks Omal :-)

priyankahdp
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
0
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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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