From c6a2d86ba6068e9e259f51a510a9c5a2e81bd18f Mon Sep 17 00:00:00 2001 From: Karuppasamy923 Date: Tue, 24 Dec 2024 13:53:25 +0530 Subject: [PATCH 1/3] fix: validate party on non receivable / payable account --- erpnext/accounts/doctype/gl_entry/gl_entry.py | 7 ++++++- erpnext/accounts/party.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index a7e7edb098dd..d9d7807a5614 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -13,7 +13,11 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( get_checks_for_pl_and_bs_accounts, ) -from erpnext.accounts.party import validate_party_frozen_disabled, validate_party_gle_currency +from erpnext.accounts.party import ( + validate_account_party_type, + validate_party_frozen_disabled, + validate_party_gle_currency, +) from erpnext.accounts.utils import get_account_currency, get_fiscal_year from erpnext.exceptions import InvalidAccountCurrency @@ -268,6 +272,7 @@ def validate_cost_center(self): def validate_party(self): validate_party_frozen_disabled(self.party_type, self.party) + validate_account_party_type(self) def validate_currency(self): company_currency = erpnext.get_company_currency(self.company) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 23b7cbec1ac8..4a58bb50da4a 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -764,6 +764,17 @@ def validate_party_frozen_disabled(party_type, party_name): frappe.msgprint(_("{0} {1} is not active").format(party_type, party_name), alert=True) +def validate_account_party_type(self): + if self.party_type and self.party: + account_type = frappe.get_cached_value("Account", self.account, "account_type") + if account_type and (account_type not in ["Receivable", "Payable"]): + frappe.throw( + _( + "Party Type and Party can only be set for Receivable / Payable account

" "{0}" + ).format(self.account) + ) + + def get_dashboard_info(party_type, party, loyalty_program=None): current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True) From a10a15b2c3ffdf0bde9873286da7c054b9af723f Mon Sep 17 00:00:00 2001 From: Karuppasamy923 Date: Tue, 24 Dec 2024 13:54:37 +0530 Subject: [PATCH 2/3] test: add unit test to validate on non receivable / payable account --- .../doctype/gl_entry/test_gl_entry.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py index 98befb4974d4..209454e7b216 100644 --- a/erpnext/accounts/doctype/gl_entry/test_gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/test_gl_entry.py @@ -78,3 +78,48 @@ def test_rename_entries(self): "SELECT current from tabSeries where name = %s", naming_series )[0][0] self.assertEqual(old_naming_series_current_value + 2, new_naming_series_current_value) + + def test_validate_account_party_type(self): + jv = make_journal_entry( + "_Test Account Cost for Goods Sold - _TC", + "_Test Bank - _TC", + 100, + "_Test Cost Center - _TC", + save=False, + submit=False, + ) + + for row in jv.accounts: + row.party_type = "Supplier" + break + + jv.save() + try: + jv.submit() + except Exception as e: + self.assertEqual( + str(e), + "Party Type and Party can only be set for Receivable / Payable account_Test Account Cost for Goods Sold - _TC", + ) + + jv1 = make_journal_entry( + "_Test Account Cost for Goods Sold - _TC", + "_Test Bank - _TC", + 100, + "_Test Cost Center - _TC", + save=False, + submit=False, + ) + + for row in jv.accounts: + row.party_type = "Customer" + break + + jv1.save() + try: + jv1.submit() + except Exception as e: + self.assertEqual( + str(e), + "Party Type and Party can only be set for Receivable / Payable account_Test Account Cost for Goods Sold - _TC", + ) From 8abbece7c4556399ddc101d8cd903ce7dd74c8db Mon Sep 17 00:00:00 2001 From: Karuppasamy923 Date: Tue, 24 Dec 2024 16:00:40 +0530 Subject: [PATCH 3/3] fix: Set account type payable for advance account --- erpnext/accounts/doctype/payment_entry/test_payment_entry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index e6c1d8fbae06..4d48f10fcde1 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -1519,7 +1519,7 @@ def test_advance_as_liability_against_order(self): parent_account="Current Liabilities - _TC", account_name="Advances Paid", company=company, - account_type="Liability", + account_type="Payable", ) frappe.db.set_value(