test: invoice outstanding when gl's are split on cost center allocat

This commit is contained in:
ruthra kumar 2022-06-24 17:36:37 +05:30
parent 71f6f78d94
commit 321fea322c

View File

@ -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()