Odoo Help


How to force commit in a loop

Jesse Rye
on 10/19/16, 4:16 PM 2,204 views

I have a button that when clicked imports records from an external source. It then loops through the records and uses .create to create the new records on the model in the database from the imported records. However it doesn't seem to commit them until its completed the loop of all imported records. Is there anyway to force the commit after each iteration?

object.create( template )
Jesse Rye
On 10/20/16, 10:27 AM

While Sah's answer appears like it should work I did some more research and found a much simpler answer for my scenario.

All I had to do was use the current environment variable and cursor and run commit(). See below.

Sah Vinay Mahabir
On 10/20/16, 7:55 AM

add this to py file
#top of the file
from odoo import api, fields, models, _, modules
from odoo.http import request
#before for loop
r = modules.registry.RegistryManager.get(dbname)
cr = r.cursor()
#inside loop
#make sure you close cr at the end of the function scope

Let me know if there is any error with your log file

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: 10/19/16, 4:16 PM
Seen: 2204 times
Last updated: 7/13/17, 5:08 PM