编程错误:无法适应类型' seniat.url' - Odoo v8到Odoo v10社区

时间:2017-04-02 04:24:22

标签: python openerp odoo-8 odoo-10

我有这个向导类:

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作为类,那么它就没用了。

顺便说一句,这是我所做的一个镜像,原始向导看起来像这样:

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

有什么想法吗?

如果您需要更多信息,请告诉我。

感谢。

1 个答案:

答案 0 :(得分:3)

_get_url 方法中存在一个问题。

odoo API搜索方法中返回浏览记录,并将其称为 RecordSet

url_ids = url.search([])

在上面的搜索行中,odoo将返回网址浏览记录。

@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  

当您调用上述方法时,您将获得网址浏览记录。

如果您需要ID列表,则需要使用ids属性。

Ex:urls.ids()

这可能会对你有帮助。