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

Onchange Methode Two Field [Closed]

By
Susi
on 12/26/14, 7:04 AM 1,147 views

The Question has been closed

by
Susi
on 01/21/2016 23:17:06

i have use onchange method in form wtc.kecamatan this is when i selected city_id provinsi_id automatically filled and its work

 def get_province_by_city(self, cr, uid, ids, city_id):
        print"--------------------------",city_id
        if city_id == city_id:
            city= self.pool.get("wtc.city").browse(cr, uid, city_id)
            return {'value': {'provinsi_id':city.provinsi_id.id}}
        return True
   

but i have another form want use onchange method.. i have field kecamatan_id , city_id and provinsi_id

i want if i selected kecamatan_id.. city_id and provinsi_id automatically filled..  like a my code above but its just 1 field that change.. whats should i add with my code above..

"if city_id == city_id:" is not required, instead use only "if city_id:"

deep
on 12/26/14, 9:23 AM
1
Susi
On 12/26/14, 9:27 PM

Hi Anand  & Atchuthan

i have use this code its work

   def name_get(self, cr, uid, ids, kecamatan_id,city_id):
        print"--------------------------",kecamatan_id
        if kecamatan_id:
            city= self.pool.get("wtc.kecamatan").browse(cr, uid, kecamatan_id)
            return {'value': {'city_id':city.city_id.id,'province_id':city.province_id.id}}

in my .xml

 <field name="kecamatan_id" on_change="name_get(kecamatan_id, city_id)"/>

but when i hit save button version error but the data successfully saved

Traceback (most recent call last): File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 499, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 516, in dispatch result = self._call_function(**self.params) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 282, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 279, in checked_call return self.endpoint(*a, **kw) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 732, in __call__ return self.method(*args, **kw) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 375, in response_wrap response = f(*args, **kw) File "/home/susi/odoo/addons/HONDA/web/controllers/main.py", line 944, in call_kw return self._call_kw(model, method, args, kwargs) File "/home/susi/odoo/addons/HONDA/web/controllers/main.py", line 925, in _call_kw names = dict(request.session.model(model).name_search('', args[0], **kwargs)) File "/home/susi/odoo/openerp-8.0/openerp/http.py", line 834, in proxy result = meth(cr, request.uid, *args, **kw) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 332, in old_api result = method(recs, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/models.py", line 1760, in name_search return self._name_search(name, args, operator, limit=limit) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 235, in wrapper return new_api(self, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 464, in new_api result = method(self._model, cr, uid, *args, **kwargs) File "/home/susi/odoo/openerp-8.0/openerp/models.py", line 1773, in _name_search res = self.name_get(cr, access_rights_uid, ids, context) File "/home/susi/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) TypeError: name_get() takes exactly 6 arguments (5 given)

 

whats should i fix with my code ??

 

 

1
Anand
On 12/26/14, 7:25 AM

in your function just add 

 def get_province_city_by_kecamatan(self, cr, uid, ids, kecamatan_id):
        print"--------------------------",city_id
        if city_id == city_id:
            city= self.pool.get("wtc.city").browse(cr, uid, city_id)
            return {'value': {'city_id':city.id,'provinsi_id':city.provinsi_id.id}}
        return True

@anand thank you its work :)

Susi
on 12/26/14, 7:36 AM

No mention

Anand
on 12/26/14, 7:38 AM

TypeError: name_get() takes exactly 6 arguments (5 given) whats should i fix with my code above?

Susi
on 12/27/14, 12:40 AM

your return value may be wrong..?

Anand
on 12/27/14, 12:53 AM

give context=true in your name_get definition...

Anand
on 12/27/14, 12:54 AM

its still error when i give code context=True in def name_get(self, cr, uid, ids, kecamatan_id,city_id, context=True):

Susi
on 12/27/14, 1:02 AM

you cant explicitly call name_get()

Anand
on 12/27/14, 1:04 AM

when i hit save button version error but the data successfully saved

Susi
on 12/27/14, 1:08 AM
0

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3918
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 12/26/14, 8:13 AM

Also, please note that for onchange return

return True            # WRONG
return {'value':{}}    # CORRECT

About This Community

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

Question tools

3 follower(s)

Stats

Asked: 12/26/14, 7:04 AM
Seen: 1147 times
Last updated: 1/21/16, 11:17 PM