diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 73c45f31ad1..47323ad0f40 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -210,19 +210,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) @@ -426,7 +427,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)