Andrius Andrius - 16 days ago 7
Python Question

Odoo - overriding old api method with new api?

I'm trying to override

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

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

Answer

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.