I need to modify the behavior of the “Enable Auto Email” from the Process statement of accounts doctype. The print format associated with statement of accounts is hard coded and I need to translate it and to add proper headers and footers. I managed to do what I want by hooking either the send mail button or the download button. Everything works as supposed. But when it automatically sends emails , it still uses the hard coded print format. I do not wish to modify this print format just in case an update or a clean install replaces my print format. I added hooks for the auto email , but I cannot , for the life of me , trigger the scheduler to send the emails as it does when it gets to midnight. Either i go to app/scheduled-job-type/process_statement_of_accounts.send_auto_email and I press execute , the last execution time changes , the job log reflects this , but no emails are ever sent. I disabled my custom app and I’m no longer hooking anything , yet the emails still don’t get created. I tried different methods from within the console but to no avail.
How can I force process_statement_of_accounts.send_auto_email to trigger properly on demand so that I dont have to wait until midnight every time I make a change to my custom app / hook ?
The execution time on the job will just show when send_auto_email was last triggered by the scheduler, which doesn’t necessarily mean that any emails were sent.
To get started with troubleshooting, the first thing I’d check is whether calling the send_emails method works as expected. It’s whitelisted, so you should be able to call it directly from the python console. If you call send_emails(psa_docname) from the console, does it send as expected?
Yes I managed to get both the download and send mail buttons to do what I want, but at that moment I didn’t specify anything about auto send thinking it would just use the send mail function… Obviously it didn’t work because the auto send doesn’t press that button and so my hook isn’t triggered… That was Friday. Came back to work today and changed things, the I looked for hours for a means to trigger the auto send mail so that I can confirm if it works on not… I would very much like to not have to wait a day to test changes I make… I’ll see in a little over an hour if the mails I receive are as I expect them to be… Otherwise, I’ll have to wait another 24h to test if I can’t figure out how to really execute the scheduler as if it were midnight…
Any pointers are appreciated. Thanks for your reply.
Hmm…I’m not really understanding your response here. Why do you you have to wait 24 hours? My suggestion was to trigger the send_emails method manually from the python console. That should send emails immediately.
Well, the first version of my app targeted only the send_mails function and when the scheduler sent me my test mail at midnight (that’s when the scheduler is set to send the auto mail) the mail received didn’t contain my newly formatted statement of account, but pressing the button in the UI sent the mail correctly… So I assumed something was different between send_auto_email and send_mail functions… But looking deeper into it this morning this might not be the case since :
def send_auto_email():
selected = frappe.get_list(
"Process Statement Of Accounts",
filters={"enable_auto_email": 1},
or_filters={"to_date": format_date(today()), "posting_date": format_date(today())},
)
for entry in selected:
send_emails(entry.name, from_scheduler=True) # ⬅️ THIS LINE
return True
send_emails is called by send_auto_email …
For some reason my hook didn’t intercept send_mails when it was called by send_auto_email the very first day I set this up.
Thanks for helping me understand that hooking send_mails should be sufficient for my needs.
I would still be nice if I could trigger the scheduler as I want so that I’m 100% sure that send_auto_mail is acting the way I truly want, because otherwise I have no choice but to wait until it runs by itself…
You definitely can trigger scheduler whenever you want, and it sounds like you were doing that above.
Are you sure that you had documents that matched the filters in the get_list call you quoted above? Especially considering that the send_emails method advances the to_date and from_date values when run, it seems very possible that the scheduler event was running correctly but just didn’t have any reports due to go out.
How do I go on about triggering the scheduler ? What I’m currently is to simple press execute on this page : app/scheduled-job-type/process_statement_of_accounts.send_auto_email
And I expect my emails to appear in the email queue , but nothing shows up.
I tested with a new process statement of accounts , with valid data when I manually press download or send email. I added the send auto mail option , with today’s date , so it has never happened yet, and then went on to execute the scheduled job type , but no emails get added to the queue.
They’re not going to show up in the queue, I don’t think, because the send_emails call passes now=True to the sendmail method. Are you sure the emails aren’t getting sent?
Oops, it seems i never pressed send on my latest reply.
The emails do show up in the queue when things work as intended.
I found my issue , my custom app wasn’t setting “true” to the scheduler , so it was bypassed. I ended up making my own scheduler job after all , because I couldn’t properly hook the function that the scheduler was triggering.
Thanks for your input , it helped guide me to my solution.