Blog: Fill The one2many fields on Onchange

Please find the below code to fill the one2many fields on ONCHANGE Method in open source ERP.

<field name=”indent_id” on_change=”onchange_indent_id(indent_id,branch_name)” attrs=”{‘invisible’:[(‘delivery_type_others’,’!=’,’direct_delivery’)],’required’:[(‘delivery_type_others’,’=’,’direct_delivery’)],’readonly’:[(‘state’,’!=’,’intransit’)]}” />

select the record in the above field to fill the onchange data in below one2many.

<field name=”receive_indent_line” nolabel=”1″ attrs=”{‘readonly’:[(‘state’,’in’,(‘done’))]}” on_change=”onchange_receive_indent_line(receive_indent_line)”>
<form string=”Material Details”>
<field name=”product_code”/>
<field name=”product_name”/>
<field name=”generic_id”/>
<field name=”batch”/>
</form>
</field>

Onchange Method for the above field:
def onchange_indent_id(self,cr,uid,ids,indent_id,branch_name):
v={}
values=[]
notes=[]
if indent_id:
line_ids = ids and self.pool.get(‘material.details’).search(cr, uid, [(‘indent_id’, ‘=’, ids[0])]) or False
if line_ids:
self.pool.get(‘material.details’).unlink(cr, uid, line_ids)
res=self.pool.get(‘res.indent’).browse(cr,uid,indent_id)
for var in res.order_line:
msg_flag=False
product_name=var.product_id.id
res1=self.pool.get(‘product.product’).browse(cr,uid,product_name)
batch_NA = ”
if res1.batch_type==’non_applicable’:
red=self.pool.get(‘res.batchnumber’).search(cr,uid,[(‘name’,’=’,product_name),(‘branch_name’,’=’,branch_name)])
for r in self.pool.get(‘res.batchnumber’).browse(cr,uid,red):
batch_NA=r.id
else:
red=self.pool.get(‘res.batchnumber’).search(cr,uid,[(‘name’,’=’,product_name),(‘branch_name’,’=’,branch_name)])
if red:
for r in self.pool.get(‘res.batchnumber’).browse(cr,uid,red):
batch_NA=False
if var.notes_one2many:
msg_flag=True
if var.source_company:
if var.state in (‘progress’,’partial_received’):
values.append({ ‘product_code’:var.product_code,
‘product_name’:var.product_id.id,
‘generic_id’:var.generic_id.id,
‘batch’:batch_NA,})
return {‘value’:{‘receive_indent_line’:values,}}

Visit Nevprobusinesssolutions.com for more information.

You must be logged in to post a comment.