Skip to Content
Menu
This question has been flagged
1 Reply
5454 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)
Avatar
Discard
Best Answer

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.


Avatar
Discard
Author

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

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

Related Posts Replies Views Activity
1
Aug 23
12546
1
Aug 23
11039
1
Jul 23
7220
4
Apr 23
8676
2
Feb 23
17590