From 388b5fb8f6155040f6d7b23fbfca0c1c72c450b9 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Fri, 1 Aug 2025 01:12:39 +0530 Subject: [PATCH 1/2] fix: do not split round off when there is a cost center allocation (cherry picked from commit f0df41d521c161a26257b0ea7321f5bcc67f05c7) --- erpnext/accounts/general_ledger.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index f2bc8b3a2f8..6dc645538f1 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -179,6 +179,15 @@ def process_gl_map(gl_map, merge_entries=True, precision=None): def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None): + round_off_account, default_currency = frappe.get_cached_value( + "Company", gl_map[0].company, ["round_off_account", "default_currency"] + ) + if not precision: + precision = get_field_precision( + frappe.get_meta("GL Entry").get_field("debit"), + currency=default_currency, + ) + new_gl_map = [] for d in gl_map: cost_center = d.get("cost_center") @@ -192,6 +201,11 @@ def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None): 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) + continue + for sub_cost_center, percentage in cost_center_allocation: gle = copy.deepcopy(d) gle.cost_center = sub_cost_center From 7a9150aac079d7c44045085695715b970ed4b94c Mon Sep 17 00:00:00 2001 From: ravibharathi656 Date: Tue, 5 Aug 2025 17:58:33 +0530 Subject: [PATCH 2/2] test: add test for cost center allocation commercial rounding (cherry picked from commit dd24cce5098be0d3abb15600b5d374559120a9ea) # Conflicts: # erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py --- .../test_cost_center_allocation.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py index 4abc82d8bec..dc73242ac06 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py +++ b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py @@ -4,6 +4,8 @@ import unittest import frappe +from frappe.query_builder.functions import Sum +from frappe.tests.utils import change_settings from frappe.utils import add_days, today from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center @@ -190,6 +192,31 @@ class TestCostCenterAllocation(unittest.TestCase): coa2.cancel() jv.cancel() + @change_settings("System Settings", {"rounding_method": "Commercial Rounding"}) + def test_debit_credit_on_cost_center_allocation_for_commercial_rounding(self): + from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice + + cca = create_cost_center_allocation( + "_Test Company", + "Main Cost Center 1 - _TC", + {"Sub Cost Center 2 - _TC": 50, "Sub Cost Center 3 - _TC": 50}, + ) + + si = create_sales_invoice(rate=145.65, cost_center="Main Cost Center 1 - _TC") + + gl_entry = frappe.qb.DocType("GL Entry") + gl_entries = ( + frappe.qb.from_(gl_entry) + .select(Sum(gl_entry.credit).as_("cr"), Sum(gl_entry.debit).as_("dr")) + .where(gl_entry.voucher_type == "Sales Invoice") + .where(gl_entry.voucher_no == si.name) + ).run(as_dict=1) + + self.assertEqual(gl_entries[0].cr, gl_entries[0].dr) + + si.cancel() + cca.cancel() + def create_cost_center_allocation( company,