TypeError: generate() takes exactly 1 argument (5 given)
TypeError: generate() takes exactly 1 argument (5 given)
我正在使用 odoo 9 并且我正在尝试使用自定义模块 "product_print_zpl_barcode " 生成标签,当我按下按钮 "Generate label " 它显示此错误任何帮助吗??
product_print_zpl_barcode.py
def generate(self):
assert self.barcode
if len(self.barcode) != 13:
raise UserError(_(
"This wizard only supports EAN13 for the moment. Barcode '%s' "
"has %d digits instead of 13") % (
self.barcode,
len(self.barcode)))
if not self.copies:
raise UserError(_("The number of copies cannot be 0"))
if self.barcode_type in ('price', 'weight'):
vals = self._prepare_price_weight_barcode_type()
elif self.barcode_type == 'product':
vals = self._prepare_product_barcode_type()
else:
raise UserError(_(
"Barcode Type %s is not supported for the moment")
% self.barcode_type)
vals.update({
'state': 'step2',
'zpl_filename': 'barcode_%s.zpl' % vals['barcode'],
})
self.write(vals)
action = self.env['ir.actions.act_window'].for_xml_id(
'product_print_zpl_barcode',
'product_print_zpl_barcode_action')
action.update({
'res_id': self.id,
'context': self._context,
'views': False})
return action
product_print_zpl_barcode_view.xml(这是按钮的动作"Generate label")
<record id="product_print_zpl_barcode_form" model="ir.ui.view">
<field name="name">product_print_zpl_barcode.form</field>
<field name="model">product.print.zpl.barcode</field>
<field name="arch" type="xml">
<form string="Generate and Print Product Barcode">
......
<footer>
<button name="generate" type="object" string="Generate Label" class="btn-primary" states="step1"/>
<button special="cancel" string="Close" class="oe_link" states="step2"/>
</footer>
</form>
</field>
</record>
回溯
Traceback (most recent call last):
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 650, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 687, in dispatch
result = self._call_function(**self.params)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 323, in _call_function
return checked_call(self.db, *args, **kwargs)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\service\model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 316, in checked_call
result = self.endpoint(*a, **kw)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 966, in __call__
return self.method(*args, **kw)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 516, in response_wrap
response = f(*args, **kw)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\addons\web\controllers\main.py", line 899, in call_button
action = self._call_kw(model, method, args, {})
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\addons\web\controllers\main.py", line 887, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
TypeError: generate() takes exactly 1 argument (5 given)
如错误所述:您正在调用带有 5 个参数的函数,它只需要 1 个:self.
你能展示调用你函数的代码吗?
我找到了我使用的答案并且有效
@api.multi
def generate(self):
assert self.barcode
if len(self.barcode) != 13:
raise UserError(_(
"This wizard only supports EAN13 for the moment. Barcode '%s' "
"has %d digits instead of 13") % (
self.barcode,
len(self.barcode)))
if not self.copies:
raise UserError(_("The number of copies cannot be 0"))
if self.barcode_type in ('price', 'weight'):
vals = self._prepare_price_weight_barcode_type()
elif self.barcode_type == 'product':
vals = self._prepare_product_barcode_type()
else:
raise UserError(_(
"Barcode Type %s is not supported for the moment")
% self.barcode_type)
vals.update({
'state': 'step2',
'zpl_filename': 'barcode_%s.zpl' % vals['barcode'],
})
self.write(vals)
action = self.env['ir.actions.act_window'].for_xml_id(
'product_print_zpl_barcode',
'product_print_zpl_barcode_action')
action.update({
'res_id': self.id,
'context': self._context,
'views': False})
return action
我正在使用 odoo 9 并且我正在尝试使用自定义模块 "product_print_zpl_barcode " 生成标签,当我按下按钮 "Generate label " 它显示此错误任何帮助吗??
product_print_zpl_barcode.py
def generate(self):
assert self.barcode
if len(self.barcode) != 13:
raise UserError(_(
"This wizard only supports EAN13 for the moment. Barcode '%s' "
"has %d digits instead of 13") % (
self.barcode,
len(self.barcode)))
if not self.copies:
raise UserError(_("The number of copies cannot be 0"))
if self.barcode_type in ('price', 'weight'):
vals = self._prepare_price_weight_barcode_type()
elif self.barcode_type == 'product':
vals = self._prepare_product_barcode_type()
else:
raise UserError(_(
"Barcode Type %s is not supported for the moment")
% self.barcode_type)
vals.update({
'state': 'step2',
'zpl_filename': 'barcode_%s.zpl' % vals['barcode'],
})
self.write(vals)
action = self.env['ir.actions.act_window'].for_xml_id(
'product_print_zpl_barcode',
'product_print_zpl_barcode_action')
action.update({
'res_id': self.id,
'context': self._context,
'views': False})
return action
product_print_zpl_barcode_view.xml(这是按钮的动作"Generate label")
<record id="product_print_zpl_barcode_form" model="ir.ui.view">
<field name="name">product_print_zpl_barcode.form</field>
<field name="model">product.print.zpl.barcode</field>
<field name="arch" type="xml">
<form string="Generate and Print Product Barcode">
......
<footer>
<button name="generate" type="object" string="Generate Label" class="btn-primary" states="step1"/>
<button special="cancel" string="Close" class="oe_link" states="step2"/>
</footer>
</form>
</field>
</record>
回溯
Traceback (most recent call last):
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 650, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 687, in dispatch
result = self._call_function(**self.params)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 323, in _call_function
return checked_call(self.db, *args, **kwargs)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\service\model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 316, in checked_call
result = self.endpoint(*a, **kw)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 966, in __call__
return self.method(*args, **kw)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\http.py", line 516, in response_wrap
response = f(*args, **kw)
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\addons\web\controllers\main.py", line 899, in call_button
action = self._call_kw(model, method, args, {})
File "D:\Projet_Odoo\odoo-9.0c-20170627\openerp\addons\web\controllers\main.py", line 887, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
TypeError: generate() takes exactly 1 argument (5 given)
如错误所述:您正在调用带有 5 个参数的函数,它只需要 1 个:self.
你能展示调用你函数的代码吗?
我找到了我使用的答案并且有效
@api.multi
def generate(self):
assert self.barcode
if len(self.barcode) != 13:
raise UserError(_(
"This wizard only supports EAN13 for the moment. Barcode '%s' "
"has %d digits instead of 13") % (
self.barcode,
len(self.barcode)))
if not self.copies:
raise UserError(_("The number of copies cannot be 0"))
if self.barcode_type in ('price', 'weight'):
vals = self._prepare_price_weight_barcode_type()
elif self.barcode_type == 'product':
vals = self._prepare_product_barcode_type()
else:
raise UserError(_(
"Barcode Type %s is not supported for the moment")
% self.barcode_type)
vals.update({
'state': 'step2',
'zpl_filename': 'barcode_%s.zpl' % vals['barcode'],
})
self.write(vals)
action = self.env['ir.actions.act_window'].for_xml_id(
'product_print_zpl_barcode',
'product_print_zpl_barcode_action')
action.update({
'res_id': self.id,
'context': self._context,
'views': False})
return action