From fc40a3c3768a107c423c2c2e87e3c464dcb2619f Mon Sep 17 00:00:00 2001 From: PRASATHRAJA <169019617+prasath-06@users.noreply.github.com> Date: Tue, 30 Sep 2025 06:38:03 -0400 Subject: [PATCH] Merge pull request #49639 from aerele/credit-limit-jv fix(Credit-limit): consider current voucher for credit limit validation (cherry picked from commit 4a01c53ccae543217400b61a9091c65d157b4acf) --- .../accounts/doctype/journal_entry/journal_entry.py | 2 +- .../doctype/journal_entry/test_journal_entry.py | 10 ++++++++++ erpnext/selling/doctype/customer/test_customer.py | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 7f71454d11d..82132ce70be 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -189,8 +189,8 @@ class JournalEntry(AccountsController): def on_submit(self): self.validate_cheque_info() - self.check_credit_limit() self.make_gl_entries() + self.check_credit_limit() self.update_asset_value() self.update_inter_company_jv() self.update_invoice_discounting() diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 0c9a20882c6..f8fde0b54bc 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -11,6 +11,7 @@ from frappe.utils import flt, nowdate from erpnext.accounts.doctype.account.test_account import get_inventory_account from erpnext.accounts.doctype.journal_entry.journal_entry import StockAccountInvalidTransaction from erpnext.exceptions import InvalidAccountCurrency +from erpnext.selling.doctype.customer.test_customer import make_customer, set_credit_limit class TestJournalEntry(unittest.TestCase): @@ -592,6 +593,15 @@ class TestJournalEntry(unittest.TestCase): self.assertEqual(jv.pay_to_recd_from, "_Test Receiver 2") + def test_credit_limit_for_customer(self): + customer = make_customer("_Test New Customer") + set_credit_limit("_Test New Customer", "_Test Company", 50) + jv = make_journal_entry(account1="Debtors - _TC", account2="_Test Cash - _TC", amount=100, save=False) + jv.accounts[0].party_type = "Customer" + jv.accounts[0].party = customer + jv.save() + self.assertRaises(frappe.ValidationError, jv.submit) + def make_journal_entry( account1, diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 90051673e70..dfb4a5b4445 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -443,3 +443,14 @@ def create_internal_customer(customer_name=None, represents_company=None, allowe customer_name = frappe.db.get_value("Customer", customer_name) return customer_name + + +def make_customer(customer_name): + if not frappe.db.exists("Customer", customer_name): + customer = frappe.new_doc("Customer") + customer.customer_name = customer_name + customer.customer_type = "Individual" + customer.insert() + return customer.name + else: + return customer_name