From 3c4e3de09b431655ec8d47f6fa3550a711bbc550 Mon Sep 17 00:00:00 2001 From: Mohd Haris Date: Sun, 14 Jun 2026 21:54:07 +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 089da1fdb2c..b00b584d768 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -613,6 +613,12 @@ class JournalEntry(AccountsController): d.idx, d.account, d.party_type ) ) + elif d.party_type or d.party: + frappe.throw( + _( + "Row {0}: Party Type and 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 581a0866721..980b920f576 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -609,6 +609,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 make_journal_entry( account1,