考虑这个功能:
@api.multi
def create_invoice(self):
""" Create a invoice refund
"""
self.ensure_one()
if not self.sure:
raise UserError(
_("Validation error!"),
_("Please confirm that you know what you're doing by"
" checking the option bellow!"))
if (self.invoice_id and self.invoice_id.company_id.jour_id and
self.invoice_id and self.invoice_id.company_id.acc_id):
inv_id = self.action_invoice_create(self,
self.invoice_id)
else:
raise UserError(
_('Validation error!'),
_("You must go to the company form and configure a journal"
" and an account for damaged invoices"))
return self.new_open_window([inv_id], 'action_invoice_tree1', 'account')
这是我从v8到v10社区的迁移。
此方法最初看起来像这样:
def create_invoice(self, cr, uid, ids, context=None):
""" Create a invoice refund
"""
context = context or {}
wizard_brw = self.browse(cr, uid, ids, context=context)
inv_id = context.get('active_id')
for wizard in wizard_brw:
if not wizard.sure:
raise osv.except_osv(
_("Validation error!"),
_("Please confirm that you know what you're doing by"
" checking the option bellow!"))
if (wizard.invoice_id and wizard.invoice_id.company_id.jour_id and
wizard.invoice_id and wizard.invoice_id.company_id.acc_id):
inv_id = self.action_invoice_create(cr, uid, ids, wizard,
wizard.invoice_id, context)
else:
raise osv.except_osv(
_('Validation error!'),
_("You must go to the company form and configure a journal"
" and an account for damaged invoices"))
return self.new_open_window(cr, uid, ids, [inv_id],
'action_invoice_tree1', 'account')
此方法检查acc_id
上是否指定了字段jour_id
和company_id
。
现在,它引发了我的注意:
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/wizard_invoice_nro_ctrl.py", line 140, in create_invoice
_("You must go to the company form and configure a journal"
TypeError: __init__() takes exactly 2 arguments (3 given)
有关于此的任何想法吗?
答案 0 :(得分:1)
您收到错误,因为 UserError 只接受一个参数&你已经通过了两个论点。
您需要使用 ValidationError
Odoo主要提供三种类型的异常警告。
1的 UserError 强>
2的 RedirectWarning 强>
3的 ValidationError 强>
UserError& ValidationError 只接受一个参数&只有向导标题消息的区别。
前:
raise ValidationError(_('A transaction can\'t have a 0 amount.'))
raise UserError(_('Error In Input Data'))
RedirectWarning 接受三个参数。
raise RedirectWarning(msg, action.id, _('Go to the configuration panel'))
第一个参数是错误消息。
重定向操作的第二个参数,您可以点击链接&在配置屏幕中重定向。
第三个参数是导航消息。