Skip to content

Commit d6903fb

Browse files
fix: Validate party on non receivable / payable account (backport frappe#44883) (frappe#44973)
* fix: validate party on non receivable / payable account (cherry picked from commit c6a2d86) * test: add unit test to validate on non receivable / payable account (cherry picked from commit a10a15b) * fix: Set account type payable for advance account (cherry picked from commit 8abbece) --------- Co-authored-by: Karuppasamy923 <[email protected]>
1 parent 9853bd9 commit d6903fb

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

erpnext/accounts/doctype/gl_entry/gl_entry.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
1414
get_checks_for_pl_and_bs_accounts,
1515
)
16-
from erpnext.accounts.party import validate_party_frozen_disabled, validate_party_gle_currency
16+
from erpnext.accounts.party import (
17+
validate_account_party_type,
18+
validate_party_frozen_disabled,
19+
validate_party_gle_currency,
20+
)
1721
from erpnext.accounts.utils import get_account_currency, get_fiscal_year
1822
from erpnext.exceptions import InvalidAccountCurrency
1923

@@ -268,6 +272,7 @@ def validate_cost_center(self):
268272

269273
def validate_party(self):
270274
validate_party_frozen_disabled(self.party_type, self.party)
275+
validate_account_party_type(self)
271276

272277
def validate_currency(self):
273278
company_currency = erpnext.get_company_currency(self.company)

erpnext/accounts/doctype/gl_entry/test_gl_entry.py

+45
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,48 @@ def test_rename_entries(self):
7979
"SELECT current from tabSeries where name = %s", naming_series
8080
)[0][0]
8181
self.assertEqual(old_naming_series_current_value + 2, new_naming_series_current_value)
82+
83+
def test_validate_account_party_type(self):
84+
jv = make_journal_entry(
85+
"_Test Account Cost for Goods Sold - _TC",
86+
"_Test Bank - _TC",
87+
100,
88+
"_Test Cost Center - _TC",
89+
save=False,
90+
submit=False,
91+
)
92+
93+
for row in jv.accounts:
94+
row.party_type = "Supplier"
95+
break
96+
97+
jv.save()
98+
try:
99+
jv.submit()
100+
except Exception as e:
101+
self.assertEqual(
102+
str(e),
103+
"Party Type and Party can only be set for Receivable / Payable account_Test Account Cost for Goods Sold - _TC",
104+
)
105+
106+
jv1 = make_journal_entry(
107+
"_Test Account Cost for Goods Sold - _TC",
108+
"_Test Bank - _TC",
109+
100,
110+
"_Test Cost Center - _TC",
111+
save=False,
112+
submit=False,
113+
)
114+
115+
for row in jv.accounts:
116+
row.party_type = "Customer"
117+
break
118+
119+
jv1.save()
120+
try:
121+
jv1.submit()
122+
except Exception as e:
123+
self.assertEqual(
124+
str(e),
125+
"Party Type and Party can only be set for Receivable / Payable account_Test Account Cost for Goods Sold - _TC",
126+
)

erpnext/accounts/doctype/payment_entry/test_payment_entry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ def test_advance_as_liability_against_order(self):
14791479
parent_account="Current Liabilities - _TC",
14801480
account_name="Advances Paid",
14811481
company=company,
1482-
account_type="Liability",
1482+
account_type="Payable",
14831483
)
14841484

14851485
frappe.db.set_value(

erpnext/accounts/party.py

+11
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,17 @@ def validate_party_frozen_disabled(party_type, party_name):
759759
frappe.msgprint(_("{0} {1} is not active").format(party_type, party_name), alert=True)
760760

761761

762+
def validate_account_party_type(self):
763+
if self.party_type and self.party:
764+
account_type = frappe.get_cached_value("Account", self.account, "account_type")
765+
if account_type and (account_type not in ["Receivable", "Payable"]):
766+
frappe.throw(
767+
_(
768+
"Party Type and Party can only be set for Receivable / Payable account<br><br>" "{0}"
769+
).format(self.account)
770+
)
771+
772+
762773
def get_dashboard_info(party_type, party, loyalty_program=None):
763774
current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True)
764775

0 commit comments

Comments
 (0)