TypeError: _get_valid_digit() takes exactly 2 arguments (1 given) - Odoo v8 to Odoo v10 community
TypeError: _get_valid_digit() takes exactly 2 arguments (1 given) - Odoo v8 to Odoo v10 community
考虑这个函数:
@api.multi
def _validate_rif(self, vat): #, cr, uid, vat, context=None
'''validates if the VE VAT NUMBER is right
@param vat: string: Vat number to Check
returns vat when right otherwise returns False
'''
if not vat:
return False
if 'VE' in vat:
vat = vat[2:]
if re.search(r'^[VJEGP][0-9]{9}$', vat):
valid_digit = self._get_valid_digit()
if valid_digit is None:
return False
if int(vat[9]) == valid_digit:
return vat
else:
self._print_error(_('Vat Error !'), _('Invalid VAT!'))
elif re.search(r'^([VE][0-9]{1,8})$', vat):
vat = vat[0] + vat[1:].rjust(8, '0')
valid_digit = self._get_valid_digit()
vat += str(valid_digit)
return vat
return False
这是我从 v8 社区迁移到 v10 社区的结果。
错误出现在这一行:valid_digit = self._get_valid_digit()
这调用了这个函数:
@api.multi
def _get_valid_digit(self, vat): #, cr, uid, vat, context=None
'''
@param vat: string
returns validating digit
'''
#vat = ''
divisor = 11
vat_type = {'V': 1, 'E': 2, 'J': 3, 'P': 4, 'G': 5}
mapper = {1: 3, 2: 2, 3: 7, 4: 6, 5: 5, 6: 4, 7: 3, 8: 2}
valid_digit = None
vat_type = vat_type.get(vat[0].upper())
if vat_type:
sum_vat = vat_type * 4
for i in range(8):
sum_vat += int(vat[i + 1]) * mapper[i + 1]
valid_digit = divisor - sum_vat % divisor
if valid_digit >= 10:
valid_digit = 0
return valid_digit
每次我点击这个按钮,它都会抛出这个:
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 64, in search_partner_seniat
res = self.env['seniat.url']._dom_giver(vat)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/seniat_url.py", line 226, in _dom_giver
vat = self._validate_rif(vat)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/seniat_url.py", line 98, in _validate_rif
valid_digit = self._get_valid_digit()
TypeError: _get_valid_digit() takes exactly 2 arguments (1 given)
这些方法原来是这样的:
def _get_valid_digit(self, cr, uid, vat, context=None):
'''
@param vat: string
returns validating digit
'''
divisor = 11
vat_type = {'V': 1, 'E': 2, 'J': 3, 'P': 4, 'G': 5}
mapper = {1: 3, 2: 2, 3: 7, 4: 6, 5: 5, 6: 4, 7: 3, 8: 2}
valid_digit = None
vat_type = vat_type.get(vat[0].upper())
if vat_type:
sum_vat = vat_type * 4
for i in range(8):
sum_vat += int(vat[i + 1]) * mapper[i + 1]
valid_digit = divisor - sum_vat % divisor
if valid_digit >= 10:
valid_digit = 0
return valid_digit
def _validate_rif(self, cr, uid, vat, context=None):
'''validates if the VE VAT NUMBER is right
@param vat: string: Vat number to Check
returns vat when right otherwise returns False
'''
if not vat:
return False
if 'VE' in vat:
vat = vat[2:]
if re.search(r'^[VJEGP][0-9]{9}$', vat):
valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
if valid_digit is None:
return False
if int(vat[9]) == valid_digit:
return vat
else:
self._print_error(_('Vat Error !'), _('Invalid VAT!'))
elif re.search(r'^([VE][0-9]{1,8})$', vat):
vat = vat[0] + vat[1:].rjust(8, '0')
valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
vat += str(valid_digit)
return vat
return False
有什么想法吗?
替换为这个
valid_digit = self._get_valid_digit(vat)
在您的原始函数中,您传递了 vat 参数。您正确地删除了在新 api 中自动传递的其他 cr、uid 和上下文参数,但是这个特定函数似乎需要 vat 参数。
考虑这个函数:
@api.multi
def _validate_rif(self, vat): #, cr, uid, vat, context=None
'''validates if the VE VAT NUMBER is right
@param vat: string: Vat number to Check
returns vat when right otherwise returns False
'''
if not vat:
return False
if 'VE' in vat:
vat = vat[2:]
if re.search(r'^[VJEGP][0-9]{9}$', vat):
valid_digit = self._get_valid_digit()
if valid_digit is None:
return False
if int(vat[9]) == valid_digit:
return vat
else:
self._print_error(_('Vat Error !'), _('Invalid VAT!'))
elif re.search(r'^([VE][0-9]{1,8})$', vat):
vat = vat[0] + vat[1:].rjust(8, '0')
valid_digit = self._get_valid_digit()
vat += str(valid_digit)
return vat
return False
这是我从 v8 社区迁移到 v10 社区的结果。
错误出现在这一行:valid_digit = self._get_valid_digit()
这调用了这个函数:
@api.multi
def _get_valid_digit(self, vat): #, cr, uid, vat, context=None
'''
@param vat: string
returns validating digit
'''
#vat = ''
divisor = 11
vat_type = {'V': 1, 'E': 2, 'J': 3, 'P': 4, 'G': 5}
mapper = {1: 3, 2: 2, 3: 7, 4: 6, 5: 5, 6: 4, 7: 3, 8: 2}
valid_digit = None
vat_type = vat_type.get(vat[0].upper())
if vat_type:
sum_vat = vat_type * 4
for i in range(8):
sum_vat += int(vat[i + 1]) * mapper[i + 1]
valid_digit = divisor - sum_vat % divisor
if valid_digit >= 10:
valid_digit = 0
return valid_digit
每次我点击这个按钮,它都会抛出这个:
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 64, in search_partner_seniat
res = self.env['seniat.url']._dom_giver(vat)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/seniat_url.py", line 226, in _dom_giver
vat = self._validate_rif(vat)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/model/seniat_url.py", line 98, in _validate_rif
valid_digit = self._get_valid_digit()
TypeError: _get_valid_digit() takes exactly 2 arguments (1 given)
这些方法原来是这样的:
def _get_valid_digit(self, cr, uid, vat, context=None):
'''
@param vat: string
returns validating digit
'''
divisor = 11
vat_type = {'V': 1, 'E': 2, 'J': 3, 'P': 4, 'G': 5}
mapper = {1: 3, 2: 2, 3: 7, 4: 6, 5: 5, 6: 4, 7: 3, 8: 2}
valid_digit = None
vat_type = vat_type.get(vat[0].upper())
if vat_type:
sum_vat = vat_type * 4
for i in range(8):
sum_vat += int(vat[i + 1]) * mapper[i + 1]
valid_digit = divisor - sum_vat % divisor
if valid_digit >= 10:
valid_digit = 0
return valid_digit
def _validate_rif(self, cr, uid, vat, context=None):
'''validates if the VE VAT NUMBER is right
@param vat: string: Vat number to Check
returns vat when right otherwise returns False
'''
if not vat:
return False
if 'VE' in vat:
vat = vat[2:]
if re.search(r'^[VJEGP][0-9]{9}$', vat):
valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
if valid_digit is None:
return False
if int(vat[9]) == valid_digit:
return vat
else:
self._print_error(_('Vat Error !'), _('Invalid VAT!'))
elif re.search(r'^([VE][0-9]{1,8})$', vat):
vat = vat[0] + vat[1:].rjust(8, '0')
valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
vat += str(valid_digit)
return vat
return False
有什么想法吗?
替换为这个
valid_digit = self._get_valid_digit(vat)
在您的原始函数中,您传递了 vat 参数。您正确地删除了在新 api 中自动传递的其他 cr、uid 和上下文参数,但是这个特定函数似乎需要 vat 参数。