I want to send notification to accounts manager just an example if for a month there are no purchase invoice is created
Here’s a step-by-step example using Python:
1.Create a scheduled custom script (hook it monthly)
Add this in your custom app’s hooks.py
:
scheduler_events = {
"monthly": [
"your_app_path.your_module.notify_if_no_purchase_invoice"
]
}
2.Create the Python method in your app** (e.g. your_module.py
):
import frappe
from frappe.utils import nowdate, get_first_day, get_last_day
def notify_if_no_purchase_invoice():
today = nowdate()
month_start = get_first_day(today)
month_end = get_last_day(today)
# Check if there are any purchase invoices this month
purchase_invoices = frappe.get_all("Purchase Invoice", filters={
"posting_date": ["between", [month_start, month_end]],
"docstatus": 1 # Submitted
})
if not purchase_invoices:
# Get email of the Accounts Manager (role-based or hardcoded)
accounts_manager_email = get_accounts_manager_email()
if accounts_manager_email:
frappe.sendmail(
recipients=[accounts_manager_email],
subject="No Purchase Invoices Created This Month",
message=f"No Purchase Invoices have been created for the month starting {month_start}. Please review the records."
)
def get_accounts_manager_email():
# Option 1: If you have a specific user
user = frappe.get_all("User", filters={"roles.role": "Accounts Manager"}, fields=["email"])
return user[0]["email"] if user else None
Tips:
- You can modify the message or filter logic (e.g., company-specific invoices).
- Make sure your scheduler is enabled:
bench --site yoursite enable-scheduler
. - You can also create this logic as a server script (type: Scheduled) if you don’t want to create a full custom app.
Perfect! If you want to do it without a script, you can still achieve this in ERPNext using the built-in tools like:
Option: Auto Email Report + Report View
Goal: Send a report every month — if there no Purchase Invoices, the report will be empty, acting as a warning.
Steps:
-
Go to:
Accounts > Reports > Purchase Invoice
-
Click “Menu” > “Save Report”
- Name:
Monthly Purchase Invoices
- Add a filter for:
- Posting Date → “This Month”
- Save it.
- Name:
-
Go to:
Settings > Auto Email Report
-
Click “New” and fill:
- Report:
Monthly Purchase Invoices
- Email To: Accounts Manager’s email
- Frequency: Monthly
- Format: HTML / Excel (your choice)
- Enable the checkbox: Send if report is blank
- Report:
-
Save and it’s done!
Result:
Each month, ERPNext will check the report.
- If there are invoices, the manager sees them.
- If none, the email will still send — and the empty table alerts them to take action.
Would you like me to help you name the saved report and configure filters more specifically (e.g., by company or status)?