[fixes] fix grand total calculation for Payment Request and set visibility of Resend Payment Email button
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.js b/erpnext/accounts/doctype/payment_request/payment_request.js
index 51ff50b..1f0e9bc 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.js
+++ b/erpnext/accounts/doctype/payment_request/payment_request.js
@@ -16,18 +16,20 @@
})
frappe.ui.form.on("Payment Request", "refresh", function(frm) {
- frm.add_custom_button(__('Resend Payment Email'), function(){
- frappe.call({
- method: "erpnext.accounts.doctype.payment_request.payment_request.resend_payment_email",
- args: {"docname": frm.doc.name},
- freeze: true,
- freeze_message: __("Sending"),
- callback: function(r){
- if(!r.exc) {
- frappe.msgprint(__("Message Sent"));
+ if(!in_list(["Initiated", "Paid"], frm.doc.status) && !frm.doc.__islocal){
+ frm.add_custom_button(__('Resend Payment Email'), function(){
+ frappe.call({
+ method: "erpnext.accounts.doctype.payment_request.payment_request.resend_payment_email",
+ args: {"docname": frm.doc.name},
+ freeze: true,
+ freeze_message: __("Sending"),
+ callback: function(r){
+ if(!r.exc) {
+ frappe.msgprint(__("Message Sent"));
+ }
}
- }
+ });
});
- });
+ }
});
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index 0ef6aa3..92ffc22 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -209,11 +209,11 @@
"""get amount based on doctype"""
if dt == "Sales Order":
base_grand_total = flt(ref_doc.base_grand_total)
- grand_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
+ grand_total = flt(ref_doc.base_grand_total) - flt(ref_doc.advance_paid) / flt(ref_doc.conversion_rate)
if dt == "Sales Invoice":
base_grand_total = flt(ref_doc.base_grand_total)
- grand_total = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
+ grand_total = flt(ref_doc.base_grand_total) - flt(ref_doc.outstanding_amount) / flt(ref_doc.conversion_rate)
if base_grand_total > 0 and grand_total > 0 :
return base_grand_total, grand_total