fix(payment_request): added permission checks on resend_payment_email

(cherry picked from commit 0659bd7049)
This commit is contained in:
diptanilsaha
2026-07-16 01:10:50 +05:30
parent c7cf9d868b
commit fcbbb251cf
2 changed files with 27 additions and 15 deletions

View File

@@ -37,6 +37,8 @@ frappe.ui.form.on("Payment Request", "refresh", function (frm) {
frm.set_intro(__("Failure: {0}", [frm.doc.failed_reason]), "red"); frm.set_intro(__("Failure: {0}", [frm.doc.failed_reason]), "red");
} }
let sending_email = false;
if ( if (
frm.doc.payment_request_type == "Inward" && frm.doc.payment_request_type == "Inward" &&
frm.doc.payment_channel !== "Phone" && frm.doc.payment_channel !== "Phone" &&
@@ -45,16 +47,16 @@ frappe.ui.form.on("Payment Request", "refresh", function (frm) {
frm.doc.docstatus == 1 frm.doc.docstatus == 1
) { ) {
frm.add_custom_button(__("Resend Payment Email"), function () { frm.add_custom_button(__("Resend Payment Email"), function () {
frappe.call({ if (sending_email) {
method: "erpnext.accounts.doctype.payment_request.payment_request.resend_payment_email", frappe.show_alert({ message: __("Sending Email"), indicator: "blue" });
args: { docname: frm.doc.name }, return;
freeze: true, }
freeze_message: __("Sending"), sending_email = true;
callback: function (r) { frappe.show_alert({ message: __("Sending Email"), indicator: "blue" });
if (!r.exc) { frm.call("resend_payment_email").then((r) => {
frappe.msgprint(__("Message Sent")); const msg = !r.exc ? __("Email Sent") : __("Email couldn't be sent.");
} frappe.show_alert({ message: msg, indicator: !r.exc ? "green" : "red" });
}, sending_email = false;
}); });
}); });
} }

View File

@@ -423,6 +423,18 @@ class PaymentRequest(Document):
return payment_entry return payment_entry
@frappe.whitelist(methods=["POST"])
def resend_payment_email(self):
if not (
self.docstatus == 1
and self.payment_request_type == "Inward"
and self.payment_channel != "Phone"
and self.status not in ["Initiated", "Paid"]
):
frappe.throw(_("Payment Link couldn't be sent."))
self.send_email()
def send_email(self): def send_email(self):
"""send email with payment link""" """send email with payment link"""
email_args = { email_args = {
@@ -440,11 +452,14 @@ class PaymentRequest(Document):
) )
], ],
} }
job_id = f"send_payment_email::{self.name}"
enqueue( enqueue(
method=frappe.sendmail, method=frappe.sendmail,
queue="short", queue="short",
timeout=300, timeout=300,
is_async=True, is_async=True,
job_id=job_id,
deduplicate=True,
enqueue_after_commit=True, enqueue_after_commit=True,
**email_args, **email_args,
) )
@@ -951,11 +966,6 @@ def get_print_format_list(ref_doctype):
return {"print_format": print_format_list} return {"print_format": print_format_list}
@frappe.whitelist()
def resend_payment_email(docname):
return frappe.get_doc("Payment Request", docname).send_email()
@frappe.whitelist() @frappe.whitelist()
def make_payment_entry(docname): def make_payment_entry(docname):
doc = frappe.get_doc("Payment Request", docname) doc = frappe.get_doc("Payment Request", docname)