Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6000 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Or

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)
Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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 !


Ảnh đại diện
Huỷ bỏ

did you resolved it?

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 23
3165
4
thg 3 22
17842
0
thg 10 20
3359
1
thg 3 16
6078
0
thg 3 15
3425