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

How to set country to customer

By
vijay
on 2/25/16, 1:35 AM 469 views

When user save the record Country will be Automatically store in database using Server action. eg:when i save the record of Customer,Country name will be Automatically store.



country_obj = self.pool.get('res.country') 
country_id = country_obj.search(cr, uid, [('name','=','india')])  
par_obj = self.pool.get('res.partner')
pat_id = par_obj.search(cr,uid,[('id', '=', uid)],context=context)
for ids in par_obj.browse(cr,uid,pat_id,context=context):
    if ids.country_id:
         par_obj.write(cr, uid,pat_id,{'country_id':country_id}, context=context)
2

Jusab Sida (jsi)

--Jusab Sida (jsi)--
Tiny ERP Pvt Ltd
http://www.odoo.com
874
| 2 1 5
Gandhinagar, India
--Jusab Sida (jsi)--


Jusab Sida (jsi)
On 2/25/16, 2:30 AM

Hi Vijay,

I have done that thing from front end through server action and automation action.

Here is server action:

####IN NEW API STYLE
country_obj = env['res.country'] 
country_id = country_obj.search([('name','=','India')])
if country_id:
object.write({'country_id':country_id[0].id})
####IN OLD API STYLE:
country_obj = self.pool.get('res.country')
country_id = country_obj.search(cr, uid, [('name','=','India')])
 if country_id:
self.pool.get('res.partner').write(cr, uid, object.id, {'country_id':country_id[0]})

Now just create one record in Automation Actions(setting>Technical>Automation>) and put your server action in Server action to run call this server action in On Creation.


its display error : write() got multiple values for keyword argument 'context'

vijay
on 2/25/16, 2:41 AM

I have just updated my answer...Here i have tested in V8 in both style..both are working...can you please try again?

Jusab Sida (jsi)
on 2/25/16, 3:49 AM

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: 2/25/16, 1:35 AM
Seen: 469 times
Last updated: 2/25/16, 4:32 AM