NeoVe
NeoVe

Reputation: 3897

TypeError: write() takes at least 5 arguments (2 given) - inherited module from v8 to v10 community

I'm migrating some modules from v8 to v10 community

This time I have this error when trying to create an invoice:

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 862, in call_kw
return self._call_kw(model, method, args, kwargs)
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 679, in call_kw
return call_kw_model(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 664, in call_kw_model
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/account/models/account_invoice.py", line 342, in create
invoice = super(AccountInvoice, self.with_context(mail_create_nolog=True)).create(vals)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/mail/models/mail_thread.py", line 227, in create
thread = super(MailThread, self).create(values)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 3798, in create
record = self.browse(self._create(old_vals))
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 3958, in _create
self.recompute()
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 5277, in recompute
recs.browse(ids)._write(dict(vals))
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/account/models/account_invoice.py", line 356, in _write
(reconciled & pre_reconciled).filtered(lambda invoice: invoice.state == 'open').action_invoice_paid()
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/account/models/account_invoice.py", line 573, in action_invoice_paid
return to_pay_invoices.write({'state': 'paid'})
TypeError: write() takes at least 5 arguments (2 given)

It doesn't says where the actual error comes in, it must be from the module I'm migrating, this is the method which has 'state' : 'paid' in my module:

@api.multi
def action_invoice_create(self, cr, uid, ids, wizard_brw, inv_brw,
                          context=None):
    """
    If the invoice has control number, this function is responsible for
    passing the bill to damaged paper
    @param wizard_brw: nothing for now
    @param inv_brw: damaged paper
    """
    invoice_line_obj = self.env('account.invoice.line')
    invoice_obj = self.env('account.invoice')
    acc_mv_obj = self.env('account.move')
    acc_mv_l_obj = self.env('account.move.line')
    tax_obj = self.env('account.invoice.tax')
    invoice = {}
    if inv_brw.nro_ctrl:
        invoice.update({
            'name': 'PAPELANULADO_NRO_CTRL_%s' % (
                inv_brw.nro_ctrl and inv_brw.nro_ctrl or ''),
            'state': 'paid',
            'tax_line': [],
        })
    else:
        raise osv.except_osv(
            _('Validation error!'),
            _("You can run this process just if the invoice have Control"
              " Number, please verify the invoice and try again."))
    invoice_obj.write(cr, uid, [inv_brw.id], invoice, context=context)
    for line in inv_brw.invoice_line:
        invoice_line_obj.write(
            cr, uid, [line.id],
            {'quantity': 0.0, 'invoice_line_tax_id': [],
             'price_unit': 0.0}, context=context)

    tax_ids = self.env('account.tax').search(cr, uid, [],
                                                  context=context)
    tax = tax_obj.search(cr, uid,
                         [('invoice_id', '=', inv_brw and inv_brw.id)],
                         context=context)
    if tax:
        tax_obj.write(cr, uid, tax[0], {'invoice_id': []}, context=context)
    tax_obj.create(cr, uid, {
        'name': 'SDCF',
        'tax_id': tax_ids and tax_ids[0],
        'amount': 0.00,
        'tax_amount': 0.00,
        'base': 0.00,
        'account_id': inv_brw.company_id.acc_id.id,
        'invoice_id': inv_brw and inv_brw.id}, {})
    move_id = inv_brw.move_id and inv_brw.move_id.id

    if move_id:
        acc_mv_obj.button_cancel(cr, uid, [inv_brw.move_id.id],
                                 context=context)
        acc_mv_obj.write(cr, uid, [inv_brw.move_id.id],
                         {'ref': 'Damanged Paper'}, context=context)
        acc_mv_l_obj.unlink(cr, uid,
                            [i.id for i in inv_brw.move_id.line_id])
    return inv_brw.id

Any ideas about this?

Since this is a code which operates on records, I've added the @api.multi decorator, but I'm not sure if this is the problem.

EDIT

This is the method on account module:

@api.multi
def action_invoice_paid(self):
    # lots of duplicate calls to action_invoice_paid, so we remove those already paid
    to_pay_invoices = self.filtered(lambda inv: inv.state != 'paid')
    if to_pay_invoices.filtered(lambda inv: inv.state != 'open'):
        raise UserError(_('Invoice must be validated in order to set it to register payemnt.'))
    if to_pay_invoices.filtered(lambda inv: not inv.reconciled):
        raise UserError(_('You cannot pay an invoice which is partially paid. You need to reconcile payment entries first.'))
    return to_pay_invoices.write({'state': 'paid'})

But I'm not sure if this is a bug, or the method from my module, which inherits account.invoice class is causing it, I think is the latter.

Upvotes: 1

Views: 1087

Answers (1)

CZoellner
CZoellner

Reputation: 14778

You're mixing up old API with new API here:

@api.multi
def action_invoice_create(
    self, cr, uid, ids, wizard_brw, inv_brw, context=None):

cr, uid, ids and context are handled by self.env so you don't need to declare them anymore. Odoo will wrap the method to old or new API style automatically, if it's needed.

New API style should be:

@api.multi
def action_invoice_create(self, wizard_brw, inv_brw):

And one more hint for Odoo 10: It's invoice_line_ids now (finally) ;-)

Upvotes: 1

Related Questions