python - Get author_id from mail_message in openERP -
i'm trying field openerps mail_message model using python code executed in server action
(so not module can debug! cannot print
in state) (when new email being fetched) unable useful it.
basicly when throwing me email, new task created openerp. newely created ticket not connected user send me mail.
when new email fetched, server action gets executed.
in table called mail_message can find email (+ author_id, + email, + res_id (which id of created task), therefore i'd fetch author_id table. (a query this: select author_id mail_message type = 'email' , res_id = '<task.id>'
)
this current code
#initialize object. 1 points mail_message model. mailmessage_obj = self.pool.get('mail.message') #created id in project_task myid = object.id #browse whole object id #message = mailmessage_obj.browse(cr,uid,[myid]) #select field messageids = mailmessage_obj.search(cr,uid,[('type','=','email'),('res_id','=',myid)],context=context) if messageids: #messagerecord = mailmessage_obj.browse(cr,uid,[myid],context=context) #object.write({'partner_id':messagerecord.author_id.id}) res = mailmessage_obj.read(messageids, ['author_id']) partnerid = res[0] #author id #partnerid = message[0]['author_id'] #partnerid = message.author_id #res = [(r['id'], r['author_id']) r in messagerecord] #partnerid = res #partnerid = 259866 object.write({'partner_id':partnerid})
i dont know how hands on author_id properly. if hardcode id , let write database (last 2 lines) it'll work fine, cant hardcode users id. ;)
could explain me how done correctly? dont know whether should use .browse or .read or else..
i think have error on python method. wrote :
res = mailmessage_obj.read(messageids, ['author_id']) partnerid = res[0]
but read() method returns here list of dict (because messageids list). then, have not specified field wanted retrieve res variable, , finally, author_id many2one, returns : (2, 'myusers').
you should have done :
res = mailmessage_obj.read(cr, uid, messageids, ['author_id']) partnerid = res[0]['author_id'][0]
hope helped you,
greatings
Comments
Post a Comment