Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Error while trying to extend onchange method in account.invoice

By
E.M.
on 9/20/15, 1:51 PM 1,070 views

I am trying to extend account.invoice with a new field which is automatically populated when customer is selected in the invoice form.

So far I am not being able to call the inherited onchange_partner_id() method with super method.

Any help is welcomed.

Code is:

# -*- coding: utf-8 -*-
from openerp import models, fields, api, exceptions

class res_partner(models.Model):

_inherit = "res.partner"
payment_method = fields.Selection(
selection=[
('bank_transfer', 'Transferencia Bancaria'),
('check', 'Cheque'),
('confirming', 'Confirming'),
('bank_giro', 'Giro'),
('promisory_note', 'Pagaré'),
('direct_debit', 'Domiciliación')
],
string='Método de pago')

class account_invoice(models.Model):

_inherit = "account.invoice"
payment_method = fields.Selection(
selection=[
('bank_transfer', 'Transferencia Bancaria'),
('check', 'Cheque'),
('confirming', 'Confirming'),
('bank_giro', 'Giro'),
('promisory_note', 'Pagaré'),
('direct_debit', 'Domiciliación')
],
string='Método de pago')

@api.model
def onchange_partner_id(self, vals):

#payment_method = res.partner.payment_method
#payment_method = ['test','TEST!']
return super(account_invoice, self).onchange_partner_id(vals)

But unfortunately I am getting the following error:

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 537, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 574, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 310, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 307, in checked_call
return self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 803, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 403, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 363, in old_api
result = method(recs, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5864, in onchange
record._onchange_eval(name, field_onchange[name], result)
File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5780, in _onchange_eval
method_res = getattr(self._model, method)(*args, context=self._context)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 335, in old_api
recs = self.browse(cr, uid, [], context)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5224, in browse
return self._browse(Environment(cr, uid, context or {}), ids)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 713, in __new__
self.cr, self.uid, self.context = self.args = (cr, uid, frozendict(context))
ValueError: dictionary update sequence element #0 has length 1; 2 is required




3

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/20/15, 4:27 PM

When you need to override a method, your method signature (it's better) have to match with the original method. For the account.invoice onchange_partner_id you need to define it like:

 @api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
    #payment_method = res.partner.payment_method
    #payment_method = ['test','TEST!']
    return super(account_invoice, self).onchange_partner_id(type, partner_id, date_invoice=date_invoice, payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)

Thanks, using the same method signature worked fine but I got crazy, restarting the odoo service and upgading the module was not enough and a full reboot was actually needed.

E.M.
on 9/21/15, 5:49 PM
3

Anil R. Kesariya

--Anil R. Kesariya--
4321
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
Anil R. Kesariya
On 9/21/15, 5:57 AM

Hi EM,

This might be helps you.

 @api.v7
def onchange_partner_id((self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
#payment_method = res.partner.payment_method
#payment_method = ['test','TEST!']
return super(account_invoice, self).onchange_partner_id((type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False)

Cheer!

Anil.


It's fully work !!! + 1

Ankit H Gandhi(AHG)
on 11/26/15, 8:05 AM
3

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 9/21/15, 3:18 AM

You should use the same definition of the function as defined in base:

@api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):

and then call its super:

res = super(account_invoice, self).onchange_partner_id(type, partner_id, date_invoice=date_invoice, payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)

then at last, append your result to the result "res" that came from super call:

res['value'].update({'payment_method':YOUR_DATA_FROM_res_partner_PAYMENT_METHOD_FIELD})
return res

Hope this will help...

Thanks Pawan, your point of extending return value is useful.

E.M.
on 9/21/15, 5:51 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/20/15, 1:51 PM
Seen: 1070 times
Last updated: 11/26/15, 8:05 AM