Hi Everyone
I want to set up a custom notification for the Purchase Invoice Doctype.
For example: A user receives a bill (Invoice Date: 01-01-25). If the user uploads the bill after 7 days (i.e., after 07-01-25), a popup should appear stating:
“The invoice date is older than the entry date. Do you want to proceed?” with the options: Yes or No.
If the user selects Yes, a notification or email should be sent to the specific Accounts team, informing them of the late upload of the bill.
or just send the mail or notification if the user uploads a bill after 7 days of the Bill Invoice date.
How can i achieve this ?
Thank You
I’m able to add the Pop Up message.
Now i’m just facing issue with the notification creation.
Any help appreciated.
Hi @rs115199789 ,
That funtionality needs to be customized at the client script level, a normal notification will not work in frappe for this requirement.
Can you please help me with that.
Thank You
Hi @rs115199789 ,
Client Script:
frappe.ui.form.on('Purchase Invoice', {
validate: function (frm) {
const invoice_date = frm.doc.bill_date;
const current_date = frappe.datetime.get_today();
// Check if invoice is older than 7 days and confirm only once
if (invoice_date && frappe.datetime.get_diff(current_date, invoice_date) > 7 && !frm._confirmation_done) {
frappe.confirm(
"The invoice date is older than the entry date. Do you want to proceed?",
function () {
// User clicked 'Yes'
frm._confirmation_done = true; // Set the flag to prevent the popup next time
frm.save(); // Proceed with the save
},
function () {
// User clicked 'No'
// frappe.throw("Please correct the Invoice Date or Entry Date.");
}
);
// Prevent auto-save until confirmation is handled
frappe.validated = false;
}
}
});
Server Script: Event (Before Insert)
def send_late_upload_notification(doc):
message = f"""
A Purchase Invoice was uploaded late:
- Invoice Date: {doc.invoice_date}
- Posting Date: {doc.posting_date}
- Uploaded By: {frappe.session.user}
"""
recipients = ["accounts_team@example.com"] # Replace with actual recipients
frappe.sendmail(
recipients=recipients,
subject="Late Invoice Upload Notification",
message=message
)
# Check if the invoice is being uploaded late (older than 7 days)
if frappe.utils.date_diff(frappe.utils.today(), doc.bill_date) > 7:
send_late_upload_notification(doc)
error for the server script
Server Scripts are disabled. Please enable server scripts from bench configuration.
Read the documentation to know more
I dont want to pay more just for a server script.a
You dont have to pay to enable server script just add a key in site config file in frappe cloud to enable.
https://frappecloud.com/docs/sites/site-config
i guess i need to create a private bench first then enable it because i tried your method and it’s not working,.
Or you can try with custom application if it is allowed to install in not private bench in frappe cloud.
nope, im trying to create a private bench will update you once it done.
till can you please look into this topic- HELP with (Client Script) Petty Cash expense not more than 10K
Can you tell me where you are entering the date?? in the Supplier Invoice Date field?
as the whole logic depends on this date field?
Also, I updated the Server Script code. Can you check it with the updated code now?
I tried to create private bench but it’s not working i need to add site in that which cause more expense.
also here is the field name.
Without server script or custom application it is not possible.
Can we create a notification ? with days after event.
Yes you can but as per the requirement popup will not be shown to proceed when you click on yes.
I dont need the pop up to proceed with yes or no it’s just for the user to view the message and it’s working already fine.
I’m just having issue with the notification.
Thank You
What issue facing in notifications?
Hi @rs115199789 ,
For this case, you can create the notification as shown in the screenshot, with the condition frappe.utils.date_diff(frappe.utils.today(), doc.bill_date) > 7
to send an email if the difference is greater than 7 days. Kindly select the accounts team’s email in the Sender field. Hope this will resolve your issue.
Hi @Rehan_Ansari
Thank you for your kind response.
can you check if i entered the information correct ?