From 1864879b9136f0ccfdbf8df31960a946d479cad2 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 22 Feb 2016 20:35:16 +0530 Subject: [PATCH] [fixes] fix grand total calculation for Payment Request and set visibility of Resend Payment Email button --- .../payment_request/payment_request.js | 24 ++++++++++--------- .../payment_request/payment_request.py | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.js b/erpnext/accounts/doctype/payment_request/payment_request.js index 51ff50bb03f..1f0e9bc9a1e 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", "onload", function(frm, dt, dn){ }) 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 0ef6aa37fc5..92ffc223bfe 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -209,11 +209,11 @@ def get_amount(ref_doc, dt): """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