Andrius Andrius - 1 year ago 121
Python Question

Odoo - overriding old api method with new api?

I'm trying to override

method, but I'm getting an error. Am I using wrong decorator? (tried,
but every one of those give an error).
For example doing this:

def compute_refund(mode='refund'):
inv_ids = self.env.context.get('active_ids', [])
for invoice in self.env['account.invoice'].browse(inv_ids):
if invoice.employee_invoice:
if mode == 'refund':
raise Warning(_("This Refund Method is not supported for employee invoices"))
if mode == 'cancel':
#Unrelate such invoice from insurance.commission.payment record
invoice.commission_payment_id = None
for line in invoice.invoice_line:
line.insurance_commission_ids.write({'state': 'confirm'})
line.insurance_commission_ids = None
return super(account_invoice_refund, self).compute_refund(mode=mode)

But it just gives this error, when trying to run the method:

Traceback (most recent call last):
File "/home/oerp/openerp80/odoo/openerp/", line 530, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/oerp/openerp80/odoo/openerp/", line 567, in dispatch
result = self._call_function(**self.params)
File "/home/oerp/openerp80/odoo/openerp/", line 303, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/oerp/openerp80/odoo/openerp/service/", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/home/oerp/openerp80/odoo/openerp/", line 300, in checked_call
return self.endpoint(*a, **kw)
File "/home/oerp/openerp80/odoo/openerp/", line 796, in __call__
return self.method(*args, **kw)
File "/home/oerp/openerp80/odoo/openerp/", line 396, in response_wrap
response = f(*args, **kw)
File "/home/oerp/openerp80/odoo/addons/web/controllers/", line 939, in call_button
action = self._call_kw(model, method, args, {})
File "/home/oerp/openerp80/odoo/addons/web/controllers/", line 927, in _call_kw
return getattr(request.registry.get(model), method)(, request.uid, *args, **kwargs)
File "/home/oerp/openerp80/odoo/openerp/", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/oerp/openerp80/odoo/addons/account/wizard/", line 231, in invoice_refund
return self.compute_refund(cr, uid, ids, data_refund, context=context)
File "/home/oerp/openerp80/odoo/openerp/", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/oerp/openerp80/odoo/openerp/", line 335, in old_api
recs = self.browse(cr, uid, [], context)
File "/home/oerp/openerp80/odoo/openerp/", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/oerp/openerp80/odoo/openerp/", line 5203, in browse
return self._browse(Environment(cr, uid, context or {}), ids)
File "/home/oerp/openerp80/odoo/openerp/", line 709, in __new__, self.uid, self.context = self.args = (cr, uid, frozendict(context))
TypeError: cannot convert dictionary update sequence element #0 to a sequence

Answer Source

I was thinking too deeply. The mistake I made was that I simply forgot to add self argument when defining method. And multi decorator was needed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download