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

Get author_id from mail_message in openERP

By
Pascal Querner
on 6/27/14, 5:21 AM 883 views

I'm trying to get a field from openERPs mail_message model using python code which is executed in a `server action` (so its not a module where I can debug! I cannot even `print` in this state) (when a new eMail is being fetched) but I am unable to get anything useful from it.

Basicly when someone is throwing me a email, a new Task is created by openERP. But the newely created ticket is not connected to the user which send me the mail.

When a new email is fetched, this server action gets executed.

In a table called mail_message you can then find the email (+ author_id, + email, + res_id (which is the id of the created Task), therefore I'd like to fetch the author_id from that table.
(A query would look like this:
`SELECT author_id FROM mail_message WHERE type = 'email' AND res_id = '<Task.id>'`)

This is my current code


    #Initialize object. That one points to the mail_message model.
    mailMessage_obj = self.pool.get('mail.message')
    
    #Created Id in project_task
    myId = object.id
    
    #browse whole object with that id
    #message = mailMessage_obj.browse(cr,uid,[myId])
    
    #Select field where 
    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']) for r in messageRecord]
    
        #partnerId = res
    
        #partnerId = 259866
        object.write({'partner_id':partnerId})

I dont know how to get my hands on the author_id properly. If I hardcode a ID and let it write to the database (last two lines) It'll work just fine, but I cant hardcode a users id. ;)

Could someone explain to me how its done correctly?
I dont know whether I should use .browse or .read or something else..

@David your code throws "AttributeError: 'browse_record_list' object has no attribute 'author_id'" object.id returns the Taskid that has been created (Not 100% sure of it, but its the best guess I currently have)

Pascal Querner
on 6/27/14, 7:25 AM
0
David Arnold
On 6/27/14, 5:44 AM

I assume object.id is something exogenous, in the scope of the information you have given. This might answer one of your question:

partnerid = mailMessage_obj.browse(cr,uid,[myId],context=context).author_id

or

message = mailMessage_obj.browse(cr,uid,[myId],context=context)
partnerid = message.author_id

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: 6/27/14, 5:21 AM
Seen: 883 times
Last updated: 3/16/15, 8:10 AM