mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-18 12:39:18 +00:00
Merge pull request #46939 from frappe/mergify/bp/version-15-hotfix/pr-39701
fix: check order paid amount before payment request (backport #39701)
This commit is contained in:
@@ -127,6 +127,8 @@ class PaymentRequest(Document):
|
|||||||
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
|
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
|
||||||
if not hasattr(ref_doc, "order_type") or ref_doc.order_type != "Shopping Cart":
|
if not hasattr(ref_doc, "order_type") or ref_doc.order_type != "Shopping Cart":
|
||||||
ref_amount = get_amount(ref_doc, self.payment_account)
|
ref_amount = get_amount(ref_doc, self.payment_account)
|
||||||
|
if not ref_amount:
|
||||||
|
frappe.throw(_("Payment Entry is already created"))
|
||||||
|
|
||||||
if existing_payment_request_amount + flt(self.grand_total) > ref_amount:
|
if existing_payment_request_amount + flt(self.grand_total) > ref_amount:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
@@ -544,6 +546,8 @@ def make_payment_request(**args):
|
|||||||
gateway_account = get_gateway_details(args) or frappe._dict()
|
gateway_account = get_gateway_details(args) or frappe._dict()
|
||||||
|
|
||||||
grand_total = get_amount(ref_doc, gateway_account.get("payment_account"))
|
grand_total = get_amount(ref_doc, gateway_account.get("payment_account"))
|
||||||
|
if not grand_total:
|
||||||
|
frappe.throw(_("Payment Entry is already created"))
|
||||||
if args.loyalty_points and args.dt == "Sales Order":
|
if args.loyalty_points and args.dt == "Sales Order":
|
||||||
from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_loyalty_points
|
from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_loyalty_points
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<p>
|
<p>
|
||||||
<a href="/api/method/erpnext.accounts.doctype.payment_request.payment_request.make_payment_request?dn={{ doc.name }}&dt={{ doc.doctype }}&submit_doc=1&order_type=Shopping Cart"
|
<a href="/api/method/erpnext.accounts.doctype.payment_request.payment_request.make_payment_request?dn={{ doc.name }}&dt={{ doc.doctype }}&submit_doc=1&order_type=Shopping Cart"
|
||||||
class="btn btn-primary btn-sm" id="pay-for-order">
|
class="btn btn-primary btn-sm" id="pay-for-order">
|
||||||
{{ _("Pay", null, "Amount") }} {{doc.get_formatted("grand_total") }}
|
{{ _("Pay", null, "Amount") }} {{ pay_amount }}
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from frappe import _
|
|||||||
|
|
||||||
from erpnext.accounts.doctype.payment_request.payment_request import (
|
from erpnext.accounts.doctype.payment_request.payment_request import (
|
||||||
ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST,
|
ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST,
|
||||||
|
get_amount,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -50,11 +51,7 @@ def get_context(context):
|
|||||||
)
|
)
|
||||||
context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
|
context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
|
||||||
|
|
||||||
context.show_pay_button = (
|
context.show_pay_button, context.pay_amount = get_payment_details(context.doc)
|
||||||
"payments" in frappe.get_installed_apps()
|
|
||||||
and frappe.db.get_single_value("Buying Settings", "show_pay_button")
|
|
||||||
and context.doc.doctype in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST
|
|
||||||
)
|
|
||||||
context.show_make_pi_button = False
|
context.show_make_pi_button = False
|
||||||
if context.doc.get("supplier"):
|
if context.doc.get("supplier"):
|
||||||
# show Make Purchase Invoice button based on permission
|
# show Make Purchase Invoice button based on permission
|
||||||
@@ -67,3 +64,19 @@ def get_attachments(dt, dn):
|
|||||||
fields=["name", "file_name", "file_url", "is_private"],
|
fields=["name", "file_name", "file_url", "is_private"],
|
||||||
filters={"attached_to_name": dn, "attached_to_doctype": dt, "is_private": 0},
|
filters={"attached_to_name": dn, "attached_to_doctype": dt, "is_private": 0},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_payment_details(doc):
|
||||||
|
show_pay_button, amount = (
|
||||||
|
(
|
||||||
|
"payments" in frappe.get_installed_apps()
|
||||||
|
and frappe.db.get_single_value("Buying Settings", "show_pay_button")
|
||||||
|
and doc.doctype in ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
if not show_pay_button:
|
||||||
|
return show_pay_button, amount
|
||||||
|
|
||||||
|
amount = get_amount(doc)
|
||||||
|
return bool(amount), amount
|
||||||
|
|||||||
Reference in New Issue
Block a user