This question has been flagged
3 Replies
43523 Views

Here is my onchange code that gets the error :

def onchange_asset_id(self,cr,uid,asset_id,qty,bal_units,context=None ):
    tot = 0
    rem = 0


    rental_id = None


    value = {'value':{'asset_id': ''}}
    with_asset = 0.0
    rental_obj = self.pool.get('fleet.rentals')            
    rental_id = context.get('rent_id')
    if rental_id:
        for rid in rental_obj.browse(cr,uid,[rental_id],context=None):

            sqlreq = "select sum(qty), asset_id " \
                     "from fleet_rentals fr ,fleet_rentals_line frl " \
                      "where fr.id = frl.rent_id and asset_id = " + str(asset_id) + " " \
                      "and frl.id != " +str(rental_id) + " " \
                      "group by  asset_id "


            cr.execute(sqlreq)

            resline =  cr.fetchall()

The error message is this :

      Server Traceback (most recent call last):
    File "/opt/openerp/server-70/openerp/addons/web/session.py", line 90, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/opt/openerp/server-70/openerp/netsvc.py", line 293, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/server-70/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/opt/openerp/server-70/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/openerp/server-70/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/openerp/server-70/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/openerp/server-70/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/openerp/biz1_addons_70/biz1_cmms/fleet.py", line 331, in onchange_asset_id
    rental_id = context.get('rent_id')
AttributeError: 'NoneType' object has no attribute 'get'
Avatar
Discard
Best Answer
 rental_id = context.get('rent_id')

The error is from this part of the code. .get function used on context is a dictionary function. But The type of context in the function here is Not a dictionary and thats why the error.

it would be better to use this code..

def onchange_asset_id(self,cr,uid,asset_id,qty,bal_units,context=None ):
    tot = 0
    rem = 0
    if context == None:
        context = {}

rental_id = None
value = {'value':{'asset_id': ''}}
with_asset = 0.0
rental_obj = self.pool.get('fleet.rentals')            

if  type(context) == dict and context.get('rent_id'):
    rental_id = context.get('rent_id')
    for rid in rental_obj.browse(cr,uid,[rental_id],context=None):

        sqlreq = "select sum(qty), asset_id " \
                 "from fleet_rentals fr ,fleet_rentals_line frl " \
                  "where fr.id = frl.rent_id and asset_id = " + str(asset_id) + " " \
                  "and frl.id != " +str(rental_id) + " " \
                  "group by  asset_id "


        cr.execute(sqlreq)

        resline =  cr.fetchall()
Avatar
Discard
Author

Thanks for the answer it solves my problem in context :D

Best Answer

do it like this. you are getting None in context thats why you got this error.

 def onchange_asset_id(self,cr,uid,asset_id,qty,bal_units,context=None ):
     if context is None:
         context = {}
Avatar
Discard
Author

Thanks for the answer it also solves my problem :D

Best Answer

The line:

for rid in rental_obj.browse(cr,uid,[rent_id],context=None):

must be

for rid in rental_obj.browse(cr,uid,[rental_id],context=None):
Avatar
Discard
Author

Thanks for the answer.. But it seems that, that is not the reason why I got my error.. I updated my post and add the error message that appears..