Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
6211 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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?

Publicaciones relacionadas Respuestas Vistas Actividad
0
mar 25
1278
0
ene 25
3358
1
ago 23
14647
1
ago 23
13296
1
jul 23
10301