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.

0

How to write domain filter onchange function for one2many field.

By
Giezel Esteves
on 9/29/16, 11:23 PM 255 views

How to write domain filter onchange function for one2many field.

0
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.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... 

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

1 follower(s)

Stats

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