2017-05-02 7 views
0

I name_search方法でres.partnerを継承し、このクラスがあります:選択しようとしたときはIndexError:範囲外のリストインデックス - Odoo v10のコミュニティにOdooのV8

class ResPartner(models.Model): 
    _inherit = 'res.partner' 

    @api.multi 
    def name_search(self, name='', args=None, operator='ilike', limit=80): #cr, uid, context=None, 
    """ 
    Gets el id of the partner with the vat or the name and return the name 
    """ 
    #if context is None: 
     #context = {} 
     self.ensure_one() 
     args = args or [] 
     ids = [] 
     if len(name) >= 2: 
      ids = self.search([('vat', operator, name)] + args, limit=limit) #cr, uid, [('vat', operator, name)] + args, limit=limit, context=context 
     if not ids: 
      ids = self.search([('name', operator, name)] + args, limit=limit) #cr, uid, [('name', operator, name)] + args, limit=limit, context=context 
     return self.name_get() #cr, uid, ids, context=context 

しかし、すべての時間が、私は請求書account.invoiceを作成するために行きますパートナー:それは私にこれを投げます:

Traceback (most recent call last): 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception 
return super(JsonRequest, self)._handle_exception(exception) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch 
result = self._call_function(**self.params) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function 
return checked_call(self.db, *args, **kwargs) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper 
return f(dbname, *args, **kwargs) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call 
result = self.endpoint(*a, **kw) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__ 
return self.method(*args, **kw) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap 
response = f(*args, **kw) 
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 862, in call_kw 
return self._call_kw(model, method, args, kwargs) 
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw 
return call_kw(request.env[model], method, args, kwargs) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 681, in call_kw 
return call_kw_multi(method, model, args, kwargs) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 668, in call_kw_multi 
ids, args = args[0], args[1:] 
IndexError: list index out of range 

私はそのクラスにいくつかの他のメソッドを持っていますが、問題のあるものは上記のものです。

def name_search(
     self, cr, uid, name='', args=None, operator='ilike', context=None, 
     limit=80): 
    """ 
    Gets el id of the partner with the vat or the name and return the name 
    """ 
    if context is None: 
     context = {} 
    args = args or [] 
    ids = [] 
    if len(name) >= 2: 
     ids = self.search(cr, uid, [('vat', operator, name)] + args, 
          limit=limit, context=context) 
    if not ids: 
     ids = self.search(cr, uid, [('name', operator, name)] + args, 
          limit=limit, context=context) 
    return self.name_get(cr, uid, ids, context=context) 

任意のアイデア:

はもともと、このメソッドは、この(バージョン8日)のように見えましたか? odooで

答えて

1

検索レコードセットは、この試す戻る:

return ids and ids.name_get() or [] 

は、私はそれを行う方法の例を編集:

def _name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100, name_get_uid=None): 
      """ 
       override the _name_search to enable searching for the identity 
       by Arabic name and French name 
      """ 
      args = [] 
      args += [ 
       '|', '|', '|', 
       ('arabic_last_name', operator, name), 
       ('arabic_first_name', operator, name), 
       ('french_last_name', operator, name), 
       ('french_first_name', operator, name) 
      ] 
      access_rights_uid = name_get_uid or user 
      ids = self._search(cr, user, args, limit=limit, context=context, access_rights_uid=access_rights_uid) 
      res = self.name_get(cr, access_rights_uid, ids, context) 
      return res 
+0

は、非常に同じ問題をありがとう:(、I場合は、好奇心に何かをtheresのをそれを@ api.modelに変更します。それはもはや発生しませんが、請求書を作成するたびに新しいクライアントを作成しなければなりません。すでに存在するかどうかは関係ありません。res.partnerにはこのname_searchメソッドがあります元々はそれが@ api.modelだと私は質問を編集するつもりだと思う – NeoVe

+0

あなたldは_name_searchをオーバーライドしてほとんど同じコードを使用します – Cherif

+0

あなたのお手伝いをするかもしれません – Cherif

関連する問題