From 71f6f78d94b4a98b7f268fdde7fd307d95db9a82 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 24 Jun 2022 13:36:15 +0530 Subject: [PATCH 1/2] fix: incorrect outstanding for invoice --- erpnext/accounts/general_ledger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 8146804705..76ef3abb6f 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -132,7 +132,7 @@ def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None): for sub_cost_center, percentage in cost_center_allocation.get(cost_center, {}).items(): gle = copy.deepcopy(d) gle.cost_center = sub_cost_center - for field in ("debit", "credit", "debit_in_account_currency", "credit_in_company_currency"): + for field in ("debit", "credit", "debit_in_account_currency", "credit_in_account_currency"): gle[field] = flt(flt(d.get(field)) * percentage / 100, precision) new_gl_map.append(gle) else: From 321fea322cf205749c60da2a71f572cfc272e56a Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 24 Jun 2022 17:36:37 +0530 Subject: [PATCH 2/2] test: invoice outstanding when gl's are split on cost center allocat --- .../sales_invoice/test_sales_invoice.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index b8154dd1f9..adac77f69d 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -792,6 +792,54 @@ class TestSalesInvoice(unittest.TestCase): jv.cancel() self.assertEqual(frappe.db.get_value("Sales Invoice", w.name, "outstanding_amount"), 562.0) + def test_outstanding_on_cost_center_allocation(self): + # setup cost centers + from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center + from erpnext.accounts.doctype.cost_center_allocation.test_cost_center_allocation import ( + create_cost_center_allocation, + ) + + cost_centers = [ + "Main Cost Center 1", + "Sub Cost Center 1", + "Sub Cost Center 2", + ] + for cc in cost_centers: + create_cost_center(cost_center_name=cc, company="_Test Company") + + cca = create_cost_center_allocation( + "_Test Company", + "Main Cost Center 1 - _TC", + {"Sub Cost Center 1 - _TC": 60, "Sub Cost Center 2 - _TC": 40}, + ) + + # make invoice + si = frappe.copy_doc(test_records[0]) + si.is_pos = 0 + si.insert() + si.submit() + + from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry + + # make payment - fully paid + pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Bank - _TC") + pe.reference_no = "1" + pe.reference_date = nowdate() + pe.paid_from_account_currency = si.currency + pe.paid_to_account_currency = si.currency + pe.source_exchange_rate = 1 + pe.target_exchange_rate = 1 + pe.paid_amount = si.outstanding_amount + pe.cost_center = cca.main_cost_center + pe.insert() + pe.submit() + + # cancel cost center allocation + cca.cancel() + + si.reload() + self.assertEqual(si.outstanding_amount, 0) + def test_sales_invoice_gl_entry_without_perpetual_inventory(self): si = frappe.copy_doc(test_records[1]) si.insert()