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

AttributeError: 'int' object has no attribute 'get'

By
Lady Sharmane Udtuhan
on 2/12/14, 4:42 AM 7,668 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'
1
Subhin P V
On 2/13/14, 1:16 AM
 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()

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

Lady Sharmane Udtuhan
on 2/13/14, 2:20 AM
1
Turkesh Patel (tpa)
On 2/13/14, 1:33 AM

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 = {}

Thanks for the answer it also solves my problem :D

Lady Sharmane Udtuhan
on 2/13/14, 2:21 AM
0

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 2/12/14, 12:21 PM

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):

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

Lady Sharmane Udtuhan
on 2/12/14, 10:22 PM

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

0 follower(s)

Stats

Asked: 2/12/14, 4:42 AM
Seen: 7668 times
Last updated: 3/16/15, 8:10 AM