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

New record created but not saved in table

By
Eric
on 12/30/13, 4:59 PM 1,319 views

Hello, I am trying to create a new record to the mail.message table with a new module that I installed. When I run the method, I get a new record id when i use the create() orm method, but the actual record isnt being saved to the table. Does anyone know why the create() is returning an id, but not saving the record to the table? Here is the code that I am using below. Thank you for your help

    mail_msg = self.pool.get('mail.message')

    # msg_ids is the id of the message 
    msg_ids = context.get('msg_id')

    # gets the message data with the id of the selected message
    message = mail_msg.browse(cr, uid, msg_ids, context)

    # finds the related partner ids and returns as a list of objects
    related_ids = mail_msg.browse(cr,uid,msg_ids,context=None)

    # will store only the ids of the partners from the related_ids list
    related_id_list = []
    for _id in related_ids.partner_ids:
        related_id_list.append(_id.id)

    values = {
        'body': message.body,
        'date': message.date,
        'subject': message.subject,
        'parent_id': message.parent_id.id,
        'res_id': related_id_list[0],   # Update this field with another partner id
        'author_id': message.author_id.id,
    }

    new_msg_created = mail_msg.create(cr, uid, values, context = None)

    # show new record id and pray it was saved to the table
    raise osv.except_osv('id number',new_msg_created)

Have you tried the same code but without raising the exception? I believe it causes a rollback to happen, which would explain the missing record.

Vizucom Oy, Timo Talvitie
on 12/30/13, 5:10 PM

Ha ha ha! wow. Thank you Timo very much. The raised exception that I was using kept the record from being inserted into the table.

Eric
on 12/30/13, 5:32 PM
0

Gustavo

--Gustavo--
950
| 2 1 4
Buenos Aires, Argentina
--Gustavo--

Python developer, big fan of sailing

Gustavo
On 1/1/14, 8:38 AM

The exception you raise is causing the problem. If you need to check whether the create function was called successfully, you should check the new_msg_created variable like this:

if not new_msg_created: # the message was not created

Now, if you need to log the successful creation (or failure to create) of the record, you can do that with the logging module:

http://docs.python.org/2/howto/logging.html

You can check the result of the logging module in the openerp-server.log file

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

0 follower(s)

Stats

Asked: 12/30/13, 4:59 PM
Seen: 1319 times
Last updated: 3/16/15, 8:10 AM