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.

0

Why does the onchange function be called after pressing Create?

By
Drees Far
on 7/22/15, 4:51 AM 373 views

Hi friends!!

Please who can help me?

I am really unable to resolve the problem.

In fact, i didnt understand the reason why the onchange is called when i press on the button create not on the field convention_id?!

Here is the code.

please help

XML:

<field name="convention_id" on_change="on_change_conventions_id(convention_id,company_id)" attrs="{'invisible': [('company_id','=',False)]}"/>

Python:

def get_inputs(self, cr, uid,ids, convention_id, company_id, context=None):

ret = []

obj = self.pool.get('seetek.convention.categorie.line')

obj_ids = obj.search(cr, uid, [('convention_id', '=', convention_id)])

res = obj.read(cr, uid, obj_ids, ['nom','nature','id'], context)

for r in res :

inputs = {

'company_convention_categorie_id': r['id'],

'company_id': company_id,

'nom': r['nom'],

'nature': r['nature'],

'actif': True,

}

ret += [inputs]

return ret

def on_change_conventions_id(self, cr, uid, ids, convention_id, company_id, context=None):

res = {'value':{'seetek_line_ids': self.get_inputs(cr, uid, ids, convention_id, company_id, context=context),

}

}

return res

1
chirag jogi
On 7/24/15, 8:45 AM

hello,

Actually on change event is called when we change field on which we have defined on change function you are getting issue while clicking on create button because you have not added if condition of field in your function

try like this,

def get_inputs(self, cr, uid,ids, convention_id, company_id, context=None):

ret = []

if convention_id:

    obj = self.pool.get('seetek.convention.categorie.line')

    obj_ids = obj.search(cr, uid, [('convention_id', '=', convention_id)])

    res = obj.read(cr, uid, obj_ids, ['nom','nature','id'], context)

    for r in res :


hope it will slove your problem...

0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 7/24/15, 8:49 AM

I have resolved the problem and it works fine:

Here is the answer:

def on_change_conventions_id(self, cr, uid, ids, convention_id, company_id, context=None):

if company_id == False:

My_error_Msg = 'Please, select your COMPANY'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

else:

res = {'value':{'seetek_line_ids': self.get_inputs(cr, uid, ids, convention_id, company_id, context=context),

}

}

return res

It works perfectly :)

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: 7/22/15, 4:51 AM
Seen: 373 times
Last updated: 7/28/15, 9:43 AM