From a3f262b415f809bc7de17192e300ca65cafb0b25 Mon Sep 17 00:00:00 2001 From: Mohd Haris Date: Tue, 16 Jun 2026 14:21:51 +0530 Subject: [PATCH] fix: restrict Party Type/Party to Receivable/Payable accounts in Journal Entry Journal Entry validation only checked party details when an account was of type Receivable/Payable, but never restricted setting a Party Type or Party against accounts of other types. This regressed v14 behavior where party info could only be captured for Receivable/Payable accounts. Add a branch to validate_party() that throws when a Party Type or Party is set on an account that is not Receivable/Payable, with a clear message. Co-Authored-By: Claude Opus 4.8 --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 6 ++++++ .../accounts/doctype/journal_entry/test_journal_entry.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 70e6164beb2..ccad6ce66ea 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -484,6 +484,12 @@ class JournalEntry(AccountsController): d.idx, d.account, d.party_type ) ) + elif d.party_type or d.party: + frappe.throw( + _( + "Row {0}: Party Type or Party can only be set for Receivable / Payable account, but account {1} is of type {2}" + ).format(d.idx, d.account, account_type or _("None")) + ) def check_credit_limit(self): customers = list( diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index a646ae64d61..bcc8ea30d2f 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -662,6 +662,13 @@ class TestJournalEntry(ERPNextTestSuite): jv.save() self.assertRaises(frappe.ValidationError, jv.submit) + def test_party_not_allowed_for_non_receivable_payable_account(self): + customer = make_customer("_Test New Customer") + jv = make_journal_entry(account1="_Test Cash - _TC", account2="_Test Bank - _TC", amount=100, save=False) + jv.accounts[0].party_type = "Customer" + jv.accounts[0].party = customer + self.assertRaises(frappe.ValidationError, jv.save) + def test_validate_reference_doc_debit_against_sales_order_throws(self): """Characterize: a debit entry linked to a Sales Order is rejected.""" from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order