From ebe09e05ec4411ae787deb99364d9607a8a74543 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Mon, 7 Oct 2024 16:08:03 +0530 Subject: [PATCH 1/4] chore: Added last empty line in PR's json --- erpnext/accounts/doctype/payment_request/payment_request.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 +} From 48d153825fb264feb16a729896a193ae90ce1489 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Mon, 7 Oct 2024 16:17:06 +0530 Subject: [PATCH 2/4] fix: Remove the `get_paid_amount_against_order` function as it is no longer used --- .../payment_request/payment_request.py | 27 ------------------- 1 file changed, 27 deletions(-) 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()` From 4444d904704aa9a4e1d118f224e87913498068a2 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Mon, 7 Oct 2024 16:24:36 +0530 Subject: [PATCH 3/4] test: Change `Accounts Settings` for multi currency (https://github.com/frappe/erpnext/pull/42427#discussion_r1789859737) --- .../doctype/payment_request/test_payment_request.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index 0b2cdef8b54..02f8e3b4e95 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -6,7 +6,7 @@ import unittest from unittest.mock import patch import frappe -from frappe.tests.utils import FrappeTestCase +from frappe.tests.utils import FrappeTestCase, change_settings from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_terms_template from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request @@ -483,8 +483,11 @@ class TestPaymentRequest(FrappeTestCase): return_doc=1, ) + @change_settings("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", @@ -585,10 +588,13 @@ class TestPaymentRequest(FrappeTestCase): self.assertEqual(pr.outstanding_amount, 0) self.assertEqual(pr.grand_total, 20000) + @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() From 3d303e7fad6dd46089a8769586b2a0e0da9ae5e5 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Mon, 7 Oct 2024 19:33:31 +0530 Subject: [PATCH 4/4] test: fixes after developed merge --- .../doctype/payment_request/test_payment_request.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index 3b75e735f66..8afb1eebc86 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -493,7 +493,7 @@ 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, do_not_save=1) @@ -599,7 +599,9 @@ class TestPaymentRequest(IntegrationTestCase): self.assertEqual(pr.outstanding_amount, 0) self.assertEqual(pr.grand_total, 20000) - @change_settings("Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1}) + @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()