gpt4 book ai didi

python - 属性错误: 'bool' object has no attribute 'pop' - Odoo v8 to Odoo v10 community

转载 作者:太空宇宙 更新时间:2023-11-03 15:26:45 25 4
gpt4 key购买 nike

我有这个方法,它是一个按钮:

@api.multi
def search_partner_seniat(self):
""" Check vat of the partner and update iva rate
"""
self.ensure_one()
vat = self.vat.upper()
res = {
'name': _('The requested contributor does not exist'),
'vat_subjected': False,
'vat': vat,
'wh_iva_agent': False,
'wh_iva_rate': 0.0
}

if 'VE' in vat:
vat = vat[2:]

# assumption: both methods in new api style
if self.env['res.partner'].check_vat_ve(vat):
res = self.env['seniat.url']._dom_giver(vat)
self.write(res)

return {
'type': 'ir.actions.act_window',
'res_model': 'search.info.partner.seniat',
'view_mode': 'form',
'view_type': 'form',
'res_id': self.id,
'views': [(False, 'form')],
'target': 'new',
}

它应该返回 res.partner 的 NIF,但每次我点击它时,它都会抛出这个:

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 866, in call_button
action = self._call_kw(model, method, args, {})
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 672, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/search_info_partner_seniat.py", line 65, in search_partner_seniat
self.write(res)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 3518, in write
vals.pop(field, None)
AttributeError: 'bool' object has no attribute 'pop'

错误出现在这里:

    if self.env['res.partner'].check_vat_ve(vat): 
res = self.env['seniat.url']._dom_giver(vat)
self.write(res)

我不知道这两个模型是否是原因,据我记得,它们在合作伙伴上运行良好:

@api.model
def check_vat_ve(self, vat): #, context=None
""" Check Venezuelan VAT number, locally called RIF.
RIF: JXXXXXXXXX RIF VENEZOLAN
IDENTIFICATION CARD: VXXXXXXXXX
FOREIGN IDENTIFICATION CARD: EXXXXXXXXX
"""

#if context is None:
#context = {}
if re.search(r'^[VJEGP][0-9]{9}$', vat):
return True
if re.search(r'^([VE][0-9]{1,8}|[D][0-9]{9})$', vat):
return True
return False

seniat_url 上:

@api.multi
def _dom_giver(self, vat):
""" Check and validates that the vat is a passport,
id or rif, to send information to SENIAT and returns the
partner info that provides.
"""
#if context is None:
#context = {}
name = ''
url_seniat = ''

url_obj = self.search([], limit=1) #self.browse(self.search([]))#[0] #(cr, uid, self.search(cr, uid, []))[0]
#url1 = url_obj.name + '%s' %(value or '')
#url2 = url_obj.url_seniat + '%s' %(value or '')
if url_obj.name:
name = url_obj.name

if url_obj.url_seniat:
url_seniat = url_obj.url_seniat
url1 = name + '%s'
url2 = url_seniat + '%s'
vat = self._validate_rif(vat) #cr, uid, vat, context=None
if vat:
return self._get_rif(vat, url1, url2) #cr, uid, vat, url1, url2, context=context
else:
return False

有什么想法吗?

这些是从 v8 社区迁移到 v10 社区的方法。

最佳答案

在写入时,您应该定义要将值写入哪些字段。所以 res 必须是一本字典。当您将该字典替换为其他内容(例如方法调用中的 False)时,它将无法将其写入字典。

我建议您使用 res.update({'dom' : self.env['seniat.url']._dom_giver(vat) })将 'dom' 替换为您要设置的变量

如果结果也可能是一个字典,您可以使用以下内容:

update_vals = self.env['seniat.url']._dom_giver(vat)
if update_vals:
res.update(update_vals)

关于python - 属性错误: 'bool' object has no attribute 'pop' - Odoo v8 to Odoo v10 community,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43082948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com