Skip to Content
Menu
This question has been flagged
1 Reply
4646 Views

How to write domain filter onchange function for one2many field.

Avatar
Discard
Best Answer

dear Giezel Esteves,

for v7:

def on_change_company_id(self, cr, uid, ids, company_id=False, context=None):
    res= {} currency_id= False
    company_journal_ids= []
    if company_id:
          company_journal_obj= self.pool.get('company.journal.configuration')
          company_journal_ids= company_journal_obj.search(cr, uid, [('company_id','=',company_id)], context=context)
    res= {'domain':{'company_ids':[('id','in',company_journal_ids)]}} return res
and then in xml:

<field name="company_id" on_change="on_change_company_id(company_id)"/>
<field name="company_ids"/>

on v8:

 @api.multi
 @api.onchange('company_id') def on_change_company_id(self):
     res= {}
     company_list= []
    if self.company_id:
        company_journal_obj= self.env['company.journal.configuration']
        company_journal_ids=company_journal_obj.search([('company_id','=', self.company_id.id)])
        for record in company_journal_ids:
             company_list.append(record.id)
    res= {'domain':{'company_ids':[('id','in',company_list)]}}
    return res

I hope I helped you... 

Avatar
Discard
Related Posts Replies Views Activity
0
Sep 23
498
0
Sep 23
451
2
Feb 23
9254
6
Oct 23
19285
3
Mar 24
7695