Odoo Help


Cannot write to database while cron job is running

Wilbert Tan
on 2/2/16, 3:29 AM 896 views

Dear guys,

I have a scheduler ( ir.cron ) that runs a function that will send email to some users.

Basically, everytime my code send the email to the user, it will write to each object ( email_sent = True ) so that the next time the scheduler run it won't send email to that user again.

But when I check, the database will only be written after the scheduler has finished running( All emails has been sent )

I need it to write to database everytime the email is sent to each user.

Anyone know how to do this?


Atul Arvind

--Atul Arvind--
| 3 3 5
vadodara, India
--Atul Arvind--


I am odoo Enthusiast/Developer from Vadodara, India. Working with odoo from v5 to v11 and other opensource technology since 5+ years. Having Strong Expertise in

Odoo Development

Odoo Customization

Odoo Training

Odoo Integration

Server Administration

Odoo Migration


Here is my StackOverflow profile.  you can also find me on LinkedIn.

Contact: atul.surficle@gmail.com.

Atul Arvind
On 2/2/16, 6:51 AM

In order to save the save the data between the scheduler run you can use cr.commit() below the code of mail send.


in mail.mail object's send method you can pass auto_commit to True. Here is a sample code

self.pool.get('mail.mail').send(cr, uid, mail_ids, auto_commit=True, raise_exception=False, context=context)
Wilbert Tan
On 2/2/16, 9:45 PM

Hi Atul, I can't comment on your submission ( not enough karma ) .

And btw, using cr.commit() actually works. But from what from what I read, it is actually not recommended to be used.

Refer here : https://www.odoo.com/forum/help-1/question/what-is-the-cr-commit-risk-how-to-safe-db-write-60885

I haven't tried the auto_commit = True as I am using ir.mail_server object to send email. Will try later.

Thank you !

did you resolved it?

on 2/9/16, 8:02 AM

@Logicious. sorry late reply. Yes I solved it using cr.commit()

Wilbert Tan
on 3/1/16, 4:41 AM

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: 2/2/16, 3:29 AM
Seen: 896 times
Last updated: 3/1/16, 4:58 AM