2017-04-02 117 views
1

我有此嚮導類:ProgrammingError:無法適應型 'seniat.url' - Odoo V8到V10 Odoo社區

from odoo import fields, models, api 


class WizardUrlSeniat(models.TransientModel): 

_name = "wizard.seniat.url" 

url1 = fields.Char(
    string='URL1', size=255, required=True, readonly=False, 
    default=lambda s: s._get_url1(), 
    help='In this field enter the URL from Seniat for search the' 
    ' fiscal information from partner') 
url2 = fields.Char(
    string='URL2', size=255, required=True, readonly=False, 
    default=lambda s: s._get_url2(), 
    help='In this field enter the URL from Seniat for search the' 
    ' retention rate from partner (RIF)') 
url3 = fields.Char(
    string='URL3', size=255, required=True, readonly=False, 
    default=lambda s: s._get_url3(), 
    help='In this field enter the URL from Seniat for search the' 
    ' retention rate from partner (CI or Passport)') 

@api.multi 
def _get_url(self): 
    """ Get seniat web page 
    """ 
    url = self.env['seniat.url'] 
    url_ids = url.search([]) 
    if len(url_ids) > 1: 
     url.unlink.self.env.url_ids[1:] 
    url_obj = self.env['seniat.url'].browse(url_ids) 
    return url_obj 
@api.multi 
def _get_url1(self): 
    url_obj = self._get_url() 
    return url_obj.name 


@api.multi 
def _get_url2(self): 
    url_obj = self._get_url() 
    return url_obj.url_seniat 

@api.multi 
def _get_url3(self): 
    url_obj = self._get_url() 
    return url_obj.url_seniat2 

@api.multi 
def update_url(self): 
    for url in self: 
     url_obj = self._get_url() 
     url_obj.write(
      {'name': url.url1, 
      'url_seniat': url.url2, 
      'url_seniat2': url.url3 
     }) 
    return {} 

每次我試試這個,我收到此錯誤:

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 679, in call_kw 
return call_kw_model(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 664, in call_kw_model 
result = method(recs, *args, **kwargs) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 1101, in default_get 
defaults[name] = field.default(self) 
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_url_seniat.py", line 41, in <lambda> 
default=lambda s: s._get_url3(), 
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_url_seniat.py", line 70, in _get_url3 
return url_obj.url_seniat2 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 860, in __get__ 
self.determine_value(record) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 960, in determine_value 
record._prefetch_field(self) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 3044, in _prefetch_field 
result = records.read([f.name for f in fs], load='_classic_write') 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 2984, in read 
self._read_from_database(stored, inherited) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 3112, in _read_from_database 
cr.execute(query_str, params) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/sql_db.py", line 141, in wrapper 
return f(self, *args, **kwargs) 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/sql_db.py", line 218, in execute 
res = self._obj.execute(query, params) 
File "/home/kristian/.virtualenvs/odoov10/local/lib/python2.7/site-packages/psycopg2/extensions.py", line 129, in getquoted 
pobjs = [adapt(o) for o in self._seq] 
ProgrammingError: can't adapt type 'seniat.url' 

錯誤出現在_get_url方法中。

我認爲問題是我打電話seniat_url這是一個類,然後它應該解析它,尋找一個字符串,應該是Char字段包含名稱或URL。

但我很困惑,因爲url_ids = url.search([])應該尋找它,但在同一時間,我已經做了url = self.env['seniat.url'],所以我不知道,如果順序是錯誤的,因爲seniat.url是模型,所以,如果我與url_ids一起工作,它已經有seniat.url作爲類,所以它沒用。

順便說一句,這是從mirgation我做,原來的嚮導是這樣的:

class WizardUrlSeniat(osv.osv_memory): 

def _get_url(self, cr, uid, ids, context=None): 
    """ Get seniat web page 
    """ 
    url = self.pool.get('seniat.url') 
    url_ids = url.search(cr, uid, []) 
    if len(url_ids) > 1: 
     url.unlink(cr, uid, url_ids[1:]) 
    url_obj = url.browse(cr, uid, url_ids, context=None)[0] 
    return url_obj 

def _get_url1(self, cr, uid, ids, context=None): 
    url_obj = self._get_url(cr, uid, ids, context) 
    return url_obj.name 

def _get_url2(self, cr, uid, ids, context=None): 
    url_obj = self._get_url(cr, uid, ids, context) 
    return url_obj.url_seniat 

def _get_url3(self, cr, uid, ids, context=None): 
    url_obj = self._get_url(cr, uid, ids, context) 
    return url_obj.url_seniat2 

def update_url(self, cr, uid, ids, context=None): 
    data = self.pool.get('wizard.seniat.url').read(cr, uid, ids)[0] 
    url_obj = self._get_url(cr, uid, ids, context) 
    url_obj.write(
     {'name': data['url1'], 
     'url_seniat': data['url2'], 
     'url_seniat2': data['url3']}) 
    return {} 

_name = "wizard.seniat.url" 
_columns = { 
    'url1': fields.char(
     string='URL1', size=255, required=True, readonly=False, 
     default=lambda s: s._get_url1(), 
     help='In this field enter the URL from Seniat for search the' 
     ' fiscal information from partner'), 
    'url2': fields.char(
     string='URL2', size=255, required=True, readonly=False, 
     default=lambda s: s._get_url2(), 
     help='In this field enter the URL from Seniat for search the' 
     ' retention rate from partner (RIF)'), 
    'url3': fields.char(
     string='URL3', size=255, required=True, readonly=False, 
     default=lambda s: s._get_url3(), 
     help='In this field enter the URL from Seniat for search the' 
     ' retention rate from partner (CI or Passport)'), 
} 

WizardUrlSeniat() 

任何想法?

如果您需要更多信息,請讓我知道。

謝謝。

回答

3

有一個問題_get_url方法。

odoo API搜索方法將返回瀏覽記錄,它被稱爲的RecordSet

url_ids = url.search([])

在上述搜索線odoo將返回的URL 瀏覽記錄。

@api.multi 
def _get_url(self): 
    """ Get seniat web page 
    """ 
    url_obj = self.env['seniat.url'] 
    urls = url_obj.search([]) 
    if len(urls) > 1: 
     urls[1:].unlink() 
    return urls 

當你調用上面的方法,那麼你會得到網址瀏覽記錄。

如果您需要ids列表,那麼您需要使用ids屬性。

例如:urls.ids()

這可能對您有所幫助。

+0

你應該擺脫術語「瀏覽記錄」;-)這個新概念被稱爲「RecordSet」。 – CZoellner

相關問題