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

Is it possible to have two onchange methods for the same field?

By
Diego Calzadilla
on 4/2/15, 4:38 PM 526 views

Hi,

Once I select a field, I need to fetch values from different tables and populate other fields: is it possible to have something like:


<field name="cm_id" on_change="on_change_cm_id(cm_id)" on_change="on_change_cm_id_2(cm_id)"/>


in my xml definition?


Thanks for suggestions!!


1
Diego Calzadilla
On 4/3/15, 12:10 AM

I answer my own question: This is no possible.


I manage to solve it in single on_change method, merging two dictionaries with values from different tables:


def on_change_cm_id(self,cr, uid, ids,cm_id,context=None):

     context=context or {} 

     application_data_product_template = []

     attributes_product_template = []

     value = {}

     dict = {}

     if ids:

             application_ids = self.pool.get('product.template.application.data.line').search(cr, uid,[('product_template_id','in',ids)])

             self.pool.get('product.template.application.data.line').unlink(cr, uid, application_ids)

             old_note_ids = self.pool.get('product.attribute.line').search(cr, uid,[('product_tmpl_id','in',ids)])

             self.pool.get('product.attribute.line').unlink(cr, uid, old_note_ids)

     application_cm_ids = []

     attribute_cm_ids = []

     attribute_cm_ids = self.pool.get('attribute.comun.denominador.line').search(cr, uid, [('comun_denominador_id', '=', cm_id)])

     application_cm_ids = self.pool.get('cm.application.data.line').search(cr, uid, [('comun_denominador_id', '=', cm_id)])

    for application_id in self.pool.get('cm.application.data.line').read(cr, uid, application_cm_ids, ['brand', 'date_beg', 'dateend', 'model']):

          application_data_product_template.append((0,0,{'brand':application_id['brand'][0],'date_beg':application_id['date_beg'], 'dateend':application_id['dateend'], 'model':application_id['model'][0]}))

    dict.update(application_data_product_template_ids=application_data_product_template)

    for attribute_id in self.pool.get('attribute.comun.denominador.line').read(cr, uid, attribute_cm_ids, ['attribute_comun_denominador_id', 'value_comun_denominador_ids']):

                attributes_product_template.append((0,0,{'value_ids':attribute_id['value_comun_denominador_ids'],'attribute_id':attribute_id['attribute_comun_denominador_id'][0]}))

    value.update(attribute_line_ids=attributes_product_template)

    value.update(dict)#in this part, dictionaries are merged!!

    return {'value':value}




Hope this is helpful for someone!!

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: 4/2/15, 4:38 PM
Seen: 526 times
Last updated: 4/3/15, 12:10 AM