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

Error in Creating Dynamic Domain for many2one field from onchange method in OpernErp v7 ???

By
saibaba
on 10/9/13, 4:00 PM 2,619 views

In my custom module i have two many2one fields ,the data in second many2one field should load dynamically depending upon the value selected in first many2one field ...So for this i called onchange method from first many2one field ,in this function i am setting the domain for second many2one field but i am not getting data with filtered records ????

sample.py

'commodity_name':fields.many2one('commodities.list','Commodity Name'),
'units':fields.many2one('units.list','Units')

def loadDataInSecondBox(self,cr,uid,ids,commodity_name)
    cond_val="Here in this variable i am getting particular id/value based on selected commodity name from database through some logic."
    domain = {'units': [('basic_unit_id', '=', cond_val)]}
    return {'domain': domain} 

   #res={'quantity':1000000000}
   #domain = {'units': [('basic_unit_id', '=', cond_val)]}
   #return {'value':res,'domain':domain,'warning':{'title':('Alert'),'message':('hello world,welcome')}}

sample_view.xml

<field name="commodity_name" on_change="loadDataInSecondBox(commodity_name)"/>
<field name="units" />

units.list in py file

class BasicUnitCreation(osv.osv):
    _name = "units.list"
    _description = "Basic Units Creation"
    _columns = {
        'name': fields.char('Unit Name', size=64, required=True),
        'basic_unit_id':fields.integer('Basic Unit Id',size=3,required=True),
        'conversion_value':fields.integer('Conversion Value',size=5,required=True),        
    }
BasicUnitCreation()
0

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 10/9/13, 7:51 PM

Try with this:

def loadDataInSecondBox(self,cr,uid,ids,commodity_name)
    cond_val="Here in this variable i am getting particular id/value based on selected commodity name from database through some logic."
    domain = {'units': [('id', '=', cond_val)]}
    return {'domain': domain}

And through cond_val send the id of the unit. Or:

def loadDataInSecondBox(self,cr,uid,ids,commodity_name)
    cond_val="Here in this variable i am getting particular id/value based on selected commodity name from database through some logic."
    domain = {'units': [('id', 'in', cond_val)]}
    return {'domain': domain}

if cond_val is a list of ids.

thanks for the reply....1)yeah as u said i tried with ('id', '=', cond_val) still i am not getting filtered data....2)cond_val is not list of ids its only a single integer value ,checked through printing in the console...

saibaba
on 10/10/13, 2:47 AM
0

IBS

--IBS--
1302
| 4 5 8
Tétouan, Morocco
--IBS--

For more informations about IBS, please visit our website at www.ibs-na.com.

For a specific questions, collaboration or help, please send us an email to support@ibs-na.com

IBS
On 10/9/13, 7:36 PM

Are you sure cond_val is filled with the right value? Did you try to output it with _logger or with osv.except_osv ?

Set it manually to a known value and see if it works.

Extra measures:

  • Restart the server.
  • Reload the browser window.

thanks a lot for your response.... i am very sure variable cond_val is getting proper integer...and manually also i gave cond_val=2...even though i am not getting filtered data...._logger or osv.except_osv i didnt get what those two terms mean ?? Extra measures taken 1)Restarted the server.2)Cleared the browser History.3)upgraded the appropriate module and base module tooo.

saibaba
on 10/10/13, 2:41 AM

is basic_unit_id a field in the units.list model? can you paste its declaration in your question.

IBS
on 10/10/13, 4:33 AM

@karim... I have updated my question pls check it...

saibaba
on 10/10/13, 6:48 AM

Please add this line raise osv.except_osv( 'Debug', 'on_change event.' ) to the beginning of your loadDataInSecondBox method and test it, this is just to be sure that the on_change event is actually being fired, you should see an exception window. Make sure to restart your server.

IBS
on 10/10/13, 12:51 PM

my method loadDataInsecondBox is getting invoked with the change in commodity name.Through that method i am returning 1) a value to other text field 2) a warning just to check its setting or not 3) domain to units field.Both 1 & 2 are working but domain is nt getting set to unit field. Please check the question i updated again....

saibaba
on 10/11/13, 3:23 AM

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: 10/9/13, 4:00 PM
Seen: 2619 times
Last updated: 3/27/15, 6:37 PM