Odoo Help


How to write domain filter onchange function for one2many field.

Giezel Esteves
on 9/29/16, 11:23 PM 1,330 views

How to write domain filter onchange function for one2many field.

ayman mohammed adam
On 10/1/16, 2:36 AM

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.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:
    res= {'domain':{'company_ids':[('id','in',company_list)]}}
    return res

I hope I helped you... 

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

1 follower(s)


Asked: 9/29/16, 11:23 PM
Seen: 1330 times
Last updated: 10/1/16, 2:36 AM