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/
I don't know about anyone, but I'd need a lot more details before I could understand your question.
@Martin, Post changed. please check & advice me
priyankahdp could you please post code of this? Github address gives 404 not found.
Dear Antanas, Link updated :-)
Thank you.