From a2b6e4a1c587ce2f7e017f39944899f76e3e2f7d Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Fri, 12 Dec 2025 12:52:04 +0530 Subject: [PATCH] fix: validate budget after cost center allocation (cherry picked from commit f9be8a46fbb64fe78f75939466dca7c2c0f5ae3d) --- erpnext/accounts/general_ledger.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index f965da928ac..13201f4bcbc 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -199,19 +199,20 @@ def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None, from_r for d in gl_map: cost_center = d.get("cost_center") + cost_center_allocation = get_cost_center_allocation_data( + gl_map[0]["company"], gl_map[0]["posting_date"], cost_center + ) + + if not cost_center_allocation: + new_gl_map.append(d) + continue + # Validate budget against main cost center if not from_repost: validate_expense_against_budget( d, expense_amount=flt(d.debit, precision) - flt(d.credit, precision) ) - cost_center_allocation = get_cost_center_allocation_data( - gl_map[0]["company"], gl_map[0]["posting_date"], cost_center - ) - if not cost_center_allocation: - new_gl_map.append(d) - continue - if d.account == round_off_account: d.cost_center = cost_center_allocation[0][0] new_gl_map.append(d) @@ -414,7 +415,11 @@ def make_entry(args, adv_adj, update_outstanding, from_repost=False): gle.flags.notify_update = False gle.submit() - if not from_repost and gle.voucher_type != "Period Closing Voucher": + if ( + not from_repost + and gle.voucher_type != "Period Closing Voucher" + and (gle.is_cancelled == 0 or gle.voucher_type == "Journal Entry") + ): validate_expense_against_budget(args)