OpenERP-7 KeyError:返回字典值时的'id'

时间:2014-05-16 14:08:55

标签: python dictionary openerp-7

我一直在研究openerp模块的开发。今天我在将字典值返回到many2one字段时遇到了一些困难。我之前成功地做了这件事但是这次我在尝试加载openerp服务器时遇到了一些错误。我检查了我的查询工作正常并带来了确切的ID和名称,但是在返回时我遇到了问题。我正在使用查询来获取ID并尝试返回它们。我的python代码是:

     import time
     from lxml import etree
     from openerp.osv import fields, osv
     from openerp import tools

     class deg_form(osv.osv):
       _name = "product.product"
       _inherit = "product.product"
       _columns = {
            'categ_temps':fields.many2one('product.category','Parent'),       
            'categ_temps':fields.function(myfunc_name, type="selection",string="Parent", method=True, store=True),  
            'categ_temp2':fields.many2one('product.category','Category'),       
            'categ_temp3':fields.many2one('product.category','Category'),        
            'my_products':fields.many2one('product.product','Parent'), 
            }


       def myfunc_name(self,cr,uid,ids,context=None):
           domain=[]
           cr.execute('select id,name from product_category where parent_id is NULL')
           res=cr.fetchall()
           for pid,name in res:
               domain.append((pid))
               print name
               return {'value':{'categ_temps':[('id','in',domain)]}}


       def Product_Category_OnChange(self,cr,uid,ids,categ_temp2):
           pro_id=[]
           cr.execute('select id,name from product_template where  categ_id in (select id from product_category where parent_id in (select id from product_category where parent_id='+str(categ_temp2)+'))  union select id,name from product_template where  categ_id in (select id from product_category where parent_id='+str(categ_temp2)+') union select id,name from product_template where categ_id='+str(categ_temp2))
           res = cr.fetchall()
       for pid,name in res:
               pro_id.append((pid))
           return {'domain':{'my_products':[('id','in',pro_id)]}}

       def create_product(self,cr,uid,ids,context):
           return{       
                 'view_type': 'form',
                 'view_mode': 'form',
                 'res_model': 'product.product',
                 'context': "{}",
                 'type': 'ir.actions.act_window'}


      _defaults = {'name':'.','categ_temps':myfunc_name}

      def show_product(self,cr,uid,ids,context):
          for id in ids:
              deg_obj=self.pool.get('product.product').browse(cr,uid,id)
              my_id=int(deg_obj.my_products)
          return{
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'product.product',
                'res_id':my_id,
                'context': "{}",
                'type': 'ir.actions.act_window'}   

deg_form()

错误详情如下:

     Client Traceback (most recent call last):
  File "/home/arsalan/openerp-7.0/openerp/addons/web/http.py", line 195, in dispatch
    response["result"] = method(self, **self.params)
  File "/home/arsalan/openerp-7.0/openerp/addons/web/controllers/main.py", line 1079, in call_kw
    return self._call_kw(req, model, method, args, kwargs)
  File "/home/arsalan/openerp-7.0/openerp/addons/web/controllers/main.py", line 1071, in _call_kw
    return getattr(req.session.model(model), method)(*args, **kwargs)
  File "/home/arsalan/openerp-7.0/openerp/addons/web/session.py", line 43, in proxy
    result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw)
  File "/home/arsalan/openerp-7.0/openerp/addons/web/session.py", line 31, in proxy_method
    result = self.session.send(self.service_name, method, *args)
  File "/home/arsalan/openerp-7.0/openerp/addons/web/session.py", line 104, in send
    raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)


Server Traceback (most recent call last):
  File "/home/arsalan/openerp-7.0/openerp/addons/web/session.py", line 90, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/home/arsalan/openerp-7.0/openerp/netsvc.py", line 295, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/arsalan/openerp-7.0/openerp/service/web_services.py", line 614, in dispatch
    res = fn(db, uid, *params)
  File "/home/arsalan/openerp-7.0/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/arsalan/openerp-7.0/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/arsalan/openerp-7.0/openerp/osv/osv.py", line 198, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/arsalan/openerp-7.0/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/arsalan/openerp-7.0/openerp/addons/product/product.py", line 234, in name_get
    reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
  File "/home/arsalan/openerp-7.0/openerp/osv/orm.py", line 3603, in read
    select = map(lambda x: isinstance(x, dict) and x['id'] or x, select)
  File "/home/arsalan/openerp-7.0/openerp/osv/orm.py", line 3603, in <lambda>
    select = map(lambda x: isinstance(x, dict) and x['id'] or x, select)
KeyError: 'id'

请指出我的错误或指导我,以便我能尽快完成工作。 问候谢谢

0 个答案:

没有答案