Odoo Help


Get author_id from mail_message in openERP

Pascal Querner
on 6/27/14, 5:21 AM 1,425 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)
        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

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


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

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/27/14, 5:21 AM
Seen: 1425 times
Last updated: 3/16/15, 8:10 AM