diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 317090e7547..8cb9eb6b5d9 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -3,11 +3,7 @@ import json import frappe from frappe import _, qb from frappe.model.document import Document -<<<<<<< HEAD from frappe.query_builder.functions import Abs, Sum -======= -from frappe.query_builder.functions import Sum ->>>>>>> f7face43cd (fix: check payments against orders for getting request amount) from frappe.utils import flt, nowdate from frappe.utils.background_jobs import enqueue @@ -686,7 +682,6 @@ def get_amount(ref_doc, payment_account=None): dt = ref_doc.doctype if dt in ["Sales Order", "Purchase Order"]: grand_total = flt(ref_doc.rounded_total) or flt(ref_doc.grand_total) - grand_total -= get_paid_amount_against_order(dt, ref_doc.name) elif dt in ["Sales Invoice", "Purchase Invoice"]: if not ref_doc.get("is_pos"): if ref_doc.party_account_currency == ref_doc.currency: @@ -708,14 +703,10 @@ def get_amount(ref_doc, payment_account=None): elif dt == "Fees": grand_total = ref_doc.outstanding_amount -<<<<<<< HEAD if grand_total > 0: return flt(grand_total, get_currency_precision()) else: frappe.throw(_("Payment Entry is already created")) -======= - return grand_total ->>>>>>> f7face43cd (fix: check payments against orders for getting request amount) def get_irequest_status(payment_requests: None | list = None) -> list: @@ -1005,7 +996,6 @@ def validate_payment(doc, method=None): ) -<<<<<<< HEAD @frappe.whitelist() def get_open_payment_requests_query(doctype, txt, searchfield, start, page_len, filters): # permission checks in `get_list()` @@ -1046,27 +1036,3 @@ def get_irequests_of_payment_request(doc: str | None = None) -> list: }, ) return res -======= -def get_paid_amount_against_order(dt, dn): - pe_ref = frappe.qb.DocType("Payment Entry Reference") - if dt == "Sales Order": - inv_dt, inv_field = "Sales Invoice Item", "sales_order" - else: - inv_dt, inv_field = "Purchase Invoice Item", "purchase_order" - inv_item = frappe.qb.DocType(inv_dt) - return ( - frappe.qb.from_(pe_ref) - .select( - Sum(pe_ref.allocated_amount), - ) - .where( - (pe_ref.docstatus == 1) - & ( - (pe_ref.reference_name == dn) - | pe_ref.reference_name.isin( - frappe.qb.from_(inv_item).select(inv_item.parent).where(inv_item[inv_field] == dn).distinct() - ) - ) - ) - ).run()[0][0] or 0 ->>>>>>> f7face43cd (fix: check payments against orders for getting request amount) diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html index f5e7dadde7f..0805a32ae33 100644 --- a/erpnext/templates/pages/order.html +++ b/erpnext/templates/pages/order.html @@ -40,11 +40,7 @@
diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py index dff982ed838..dcf3b046722 100644 --- a/erpnext/templates/pages/order.py +++ b/erpnext/templates/pages/order.py @@ -4,13 +4,10 @@ import frappe from frappe import _ -<<<<<<< HEAD from erpnext.accounts.doctype.payment_request.payment_request import ( ALLOWED_DOCTYPES_FOR_PAYMENT_REQUEST, + get_amount, ) -======= -from erpnext.accounts.doctype.payment_request.payment_request import get_amount ->>>>>>> c18ff5bd25 (fix(portal): payment amount for orders) def get_context(context): @@ -54,15 +51,7 @@ def get_context(context): ) context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points")) -<<<<<<< HEAD - context.show_pay_button = ( - "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_pay_button, context.pay_amount = get_payment_details(context.doc) ->>>>>>> c18ff5bd25 (fix(portal): payment amount for orders) context.show_make_pi_button = False if context.doc.get("supplier"): # show Make Purchase Invoice button based on permission @@ -79,10 +68,15 @@ def get_attachments(dt, dn): 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") - ), 0 + ( + "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