KeyError:' url_ids' - 从v8到v10社区的Odoo模块灌溉

时间:2017-03-19 04:40:56

标签: python openerp odoo-8 odoo-10

我有这堂课:

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['url_ids'].browse() 
    return url_obj 

@api.multi
def _get_url1(self): 
    url_obj = self._get_url() 


@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

当我从菜单项点击url3时,它会抛出这个:

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 69, in _get_url3
url_obj = self._get_url() #(self.env.cr) 
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_url_seniat.py", line 53, in _get_url
url_obj = self.env['url_ids'].browse() 
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 752, in __getitem__
return self.registry[model_name]._browse((), self)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/modules/registry.py", line 170, in __getitem__
return self.models[model_name]
KeyError: 'url_ids'

错误正好来自default=lambda s: s._get_url3(),字段的url3。 来自url_obj = self._get_url()的{​​{1}}和来自第一种方法_get_url3()的{​​{1}}。

这是一个我从v8迁移到v10的模块,它几乎已经完成了,但有些东西我在这里看不到。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

请检查模块中是否正确定义了对象&#39; url_ids&#39; 。尝试浏览该对象时抛出错误。

希望这有帮助。

答案 1 :(得分:0)

代码的这一行:

    url_obj = self.env['url_ids'].browse() 

什么是 url_ids ,如果它是某个型号名称,则不应该遵循点约定(不重要),就像它应该 url.ids 并记住 self.env 将模型名称作为键。

如果您尝试浏览从此处搜索检索到的 url_ids

url = self.env['seniat.url']
url_ids = url.search([]) 

然后你应该这样做:

browse_records = self.env['seniat.url'].browse(url_ids)

将返回 url_ids

的浏览记录