diff --git a/erpnext/accounts/doctype/payment_request/payment_request.json b/erpnext/accounts/doctype/payment_request/payment_request.json index 36ef7a59ca8..a25c7208d33 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.json +++ b/erpnext/accounts/doctype/payment_request/payment_request.json @@ -482,4 +482,4 @@ "sort_field": "creation", "sort_order": "DESC", "states": [] -} \ No newline at end of file +} diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 87cd23c25ba..e23187770f9 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -883,33 +883,6 @@ def validate_payment(doc, method=None): ) -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 - - @frappe.whitelist() def get_open_payment_requests_query(doctype, txt, searchfield, start, page_len, filters): # permission checks in `get_list()` diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index 8ceb73176b1..8afb1eebc86 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -493,10 +493,12 @@ class TestPaymentRequest(IntegrationTestCase): ) @IntegrationTestCase.change_settings( - "Accounts Settings", allow_multi_currency_invoices_against_single_party_account=1 + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} ) def test_multiple_payment_if_partially_paid_for_multi_currency(self): - pi = make_purchase_invoice(currency="USD", conversion_rate=50, qty=1, rate=100) + pi = make_purchase_invoice(currency="USD", conversion_rate=50, qty=1, rate=100, do_not_save=1) + pi.credit_to = "Creditors - _TC" + pi.submit() pr = make_payment_request( dt="Purchase Invoice", @@ -597,10 +599,15 @@ class TestPaymentRequest(IntegrationTestCase): self.assertEqual(pr.outstanding_amount, 0) self.assertEqual(pr.grand_total, 20000) + @IntegrationTestCase.change_settings( + "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + ) def test_single_payment_with_payment_term_for_multi_currency(self): create_payment_terms_template() - si = create_sales_invoice(do_not_save=1, currency="USD", qty=1, rate=200, conversion_rate=50) + si = create_sales_invoice( + do_not_save=1, currency="USD", debit_to="Debtors - _TC", qty=1, rate=200, conversion_rate=50 + ) si.payment_terms_template = "Test Receivable Template" # 84.746 and 15.254 si.save() si.submit()