Search code examples
python-2.7odoo-9

TypeError: generate() takes exactly 1 argument (5 given)


I'm using odoo 9 and i'm tring to generate label with the custom module "product_print_zpl_barcode " when i press on the button "Generate label " it shows this error any help please ??

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 (This is the action of the button "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

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)

Solution

  • i find the answer i used and it works

    @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