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

I need to send out a mail when a PoS session is closed:

@api.multi
@api.constrains('state')
def _session_resume(self):
    if self.state == 'closed':
        print 'closed'
        mail = self.env['mail.mail']
mail_data = {'subject': 'closing session : ' + datetime.now().strftime("%d-%m-%Y"), 'body_html': 'test', 'email_from': '******@gmail.com', 'email_to': '******@gmail.com'}
        mail_out = mail.create(mail_data)
        mail.send(mail_out)

I can reach without issues the api.constrains statement, but no mail is coming out, at least not immediately. 
Forcing an email cron job on automation/ scheduled actions  I can clearly see an email log "successfully sent" and my mail is delivered:

2019-01-28 19:37:58,179 1164 INFO db02 odoo.addons.mail.models.mail_mail: Mail with ID 6 and
Message-Id u'<1548704145.344115972518921.633285188501212-openerp-private@HP-Note>' successfully sent

Then how can I force an immediate email from my python code without edit the stock time (1 hour) in Email Queue Manager?

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

Hi,

please try with "force_send=True" parameter.
as per  your Example : mail.send(force_send=True)
Thanks.

Ảnh đại diện
Huỷ bỏ
Tác giả

No, it rise an error...

Error while validating constraint

send() got an unexpected keyword argument 'force_send'

Hello,

so you need to duration of Cron Job is decrease as per your needs.

i think it's a better option in this case.

Thanks

Tác giả

That's not logic, but ok. Is what I'm doing now.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 24
2139
3
thg 11 21
9322
0
thg 3 21
6717
0
thg 3 21
2938
3
thg 7 20
21094