This question has been flagged
8 Replies
6758 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()
Avatar
Discard
Best Answer

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.
Avatar
Discard
Author

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.

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

Author

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

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.

Author

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

Best Answer

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.

Avatar
Discard
Author

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